// Start is called before the first frame update void Start() { currentState = patrolState; SetCloseTarget(); currentState.StartState(); }
// Update is called once per frame void Update() { // Update current state currentState.UpdateState(); // Detect state change and call StartState method in current state if (previousState != null && previousState != currentState) { Debug.Log("State changed! " + previousState + " -> " + currentState); // Activate start state currentState.StartState(); } // Update previous state previousState = currentState; }