// Update is called once per frame void Update() { NPCStateMachine.UpdateState(); if (transform.position.x >= 105) { NPCStateMachine.ChangeState(new WalkLeft(this.gameObject, NPCStateMachine)); } else if (transform.position.x <= -105) { NPCStateMachine.ChangeState(new WalkRight(this.gameObject, NPCStateMachine)); } }
// Use this for initialization void Start() { NPCStateMachine = new NpcStateMachineMgr(); NPCStateMachine.currentStateName = NpcStateMachineMgr.NPCStates.NONE; int startDir = Random.Range(0, 2); if (startDir == 0) { NPCStateMachine.ChangeState(new WalkLeft(this.gameObject, NPCStateMachine)); //call a new state to switch to in the beginning //Debug.Log("Starting left!"); } else if (startDir == 1) { NPCStateMachine.ChangeState(new WalkRight(this.gameObject, NPCStateMachine)); //call a new state to switch to in the beginning //Debug.Log("Starting right!"); } speed = Random.Range(0.1f, 0.5f); }