//Create listener function to know when the enmy stops following void EnemyStateChanged(EnemyBehaviour.State NewState) { if (NewState == EnemyBehaviour.State.Walking || NewState == EnemyBehaviour.State.Idle) { //Stops listening to enamy and clean enemySelector EnemyFollowing.GetComponent <EnemyBehaviour>().ChangeState -= EnemyStateChanged; EnemyFollowing = null; } }
public void ChangeState(string _name) { foreach (State state in States) { if (state.Name == _name) { _currentState = state; _currentState.StoreController(this); return; } } Debug.LogError("[ERROR] No state with the name '" + _name + "' exists!"); }