public static event Action <EnemyBehaviour> OnDie; //Send message to game manager, might be sent from player void Start() //or Awake()? or OnEnable()? { player = GameObject.FindWithTag("Player"); enemyRB = GetComponent <Rigidbody2D>(); moveLeft = new moveLeft(); moveRight = new moveRight(); idle = new idle(); jump = new jump(); moveToLocation = new moveToLocation(); //add behavior to command list patrolingBehaviorCommands.Add(moveLeft); patrolingBehaviorCommands.Add(moveLeft); patrolingBehaviorCommands.Add(moveLeft); patrolingBehaviorCommands.Add(moveLeft); patrolingBehaviorCommands.Add(moveLeft); patrolingBehaviorCommands.Add(moveRight); patrolingBehaviorCommands.Add(moveRight); patrolingBehaviorCommands.Add(moveRight); patrolingBehaviorCommands.Add(moveRight); patrolingBehaviorCommands.Add(moveRight); //chaseBehaviorCommands.Add(moveToLocation); patrolSlot = maxPatrolSlot; chaseSlot = maxChaseSlot; Invoke("EnemyPatrol", UnityEngine.Random.Range(0.2f, 2f)); //Cheat to make the goombas behave not in unison }
IEnumerator ChasingPlayer() { chaseSlot -= 1; #region Chase Command Lists //execute chasing command list Vector2 destination = new Vector2(player.transform.position.x, player.transform.position.y); Vector3 enemyDes = destination; moveToLocation = new moveToLocation(); moveToLocation.Execute(enemy, destination, speed, moveLeft); Debug.Log("Moving from " + enemy.position + "to " + enemyDes + " with speed " + speed + " chase slot = " + chaseSlot); yield return(new WaitUntil(() => enemy.position == enemyDes)); //yield return from the last action on the list #endregion //yield return new WaitForSeconds(3f); //temp StopCoroutine(ChasingPlayer()); //Not sure if we need to stop coroutine here DoChase(); //Start over the chase }