private void OnEnable() { _current = Instantiate(startState); _current.OnEnter(gameObject); if (UnityEngine.Random.value > 0.99f) { PlayerAudioBehaviour.PlaySound(EAudioEventType.zombieGrowl, transform.position); } }
private void Update() { _current.Update(); if (_current.IsCompleted()) { _current.OnLeave(); var transitsTo = _current.TransitTo(); if (transitsTo != null && states.Contains(transitsTo)) { Destroy(_current); _current = Instantiate(transitsTo); _current.OnEnter(gameObject); } else { Debug.LogError(string.Format("Next logical step for {0} is oblivion!", gameObject.name)); Destroy(gameObject); } } }