public override void Execute(EnemyController enemyController) { PatrolController patrolController = (PatrolController)enemyController; if (!_currentState.checkValid(patrolController) || _isFinished) { // randomly change current state int randomStateCase; do { randomStateCase = UnityEngine.Random.Range(0, 3); } while (randomStateCase == _currentStateCase); _currentStateCase = randomStateCase; switch (_currentStateCase) { case 0: _currentState = new Idle(); break; case 1: _currentState = new WalkingLeft(); break; case 2: _currentState = new WalkingRight(); break; } patrolController.StartCoroutine(executeCoroutine(patrolController.behaveInterval())); } _currentState.Execute(patrolController); }