private void SetState(State state, float delay = 0) { if (delay > 0) { StartCoroutine(SetStateWithDelay(state, delay)); return; } if (this.state == state) { return; } // exit switch (this.state) { case State.IDLE: break; case State.WALKING: break; } this.state = state; // enter switch (this.state) { case State.IDLE: WalkTo(overflow.position, () => { Debug.Log("Destination reached"); }); break; case State.WALKING: break; case State.OVERFLOW: WalkTo(overflow.position, () => { Debug.Log("Oerflow reached " + name); Destroy(gameObject); }); break; case State.DESTINATION: WalkTo(destination.position, () => { Debug.Log("Destination reached " + name); Destroy(gameObject); }); break; case State.QUEUE: EntityQueueSpot spot = queue.FindEmptySpot(); // we want to know if this spot is taken before we get to it enterQueueCount++; WalkTo(spot.transform.position, () => { Debug.Log("Destination reached " + name); if (Enter(spot)) { // we are in spot, waiting to move to next spot SetState(State.IN_QUEUE); } else { TryQueue(); } }); spot.Incoming(gameObject, () => { TryQueue(); }); break; } }