void Update() { switch (_state) { case WarriorState.Idle: _state = WarriorState.FindTarget; break; case WarriorState.FindTarget: var target = FindEnemy(); if (target) { _target.SetTarget(target.gameObject); _state = WarriorState.MovingToTarget; _goTo.enabled = true; } break; case WarriorState.MovingToTarget: if (!_target.HasTarget()) { _goTo.enabled = false; _state = WarriorState.Idle; } break; } }
void Update() { switch (_state) { case CollectorState.Idle: _state = CollectorState.FindResource; break; case CollectorState.FindResource: var target = FindResource(targetType); if (target) { _target.SetTarget(target.gameObject); _state = CollectorState.MovingToResource; _goTo.enabled = true; } break; case CollectorState.MovingToResource: if (_goTo.IsNear(collectDistance)) { _goTo.enabled = false; _state = CollectorState.CollectingResource; _collect.enabled = true; } break; case CollectorState.CollectingResource: if (!_collect.CanCollect()) { _collect.enabled = false; _state = CollectorState.FindHub; } break; case CollectorState.FindHub: var hub = FindStorage(targetType); if (hub) { _target.SetTarget(hub.gameObject); _state = CollectorState.MovingToHub; _goTo.enabled = true; } break; case CollectorState.MovingToHub: if (_goTo.IsNear(unloadDistance)) { _goTo.enabled = false; _state = CollectorState.UnloadResources; _unload.enabled = true; } break; case CollectorState.UnloadResources: if (!_unload.CanUnload()) { _unload.enabled = false; _state = CollectorState.Idle; } break; } }