// Update is called once per frame void Update() { // Check if another task was assigned. In this case, // combat mode should be left. if (_states.GetTask() != EAntTasks.Attack) { _states.currentState = EAntStates.Idle; return; } // If changed to combat mode if (_attack.HasTarget() && !_inCombat) { _inCombat = true; _pheromonePlacement.SetPheromoneType(EPheromoneTypes.Attack); return; } // If target was lost (and possibly was in combat mode) if (!_attack.HasTarget()) { _inCombat = false; _states.currentState = EAntStates.Idle; return; } // We are in combat so update combat circling. if (_inCombat) { GameObject target = _attack.GetCurrentTarget(); Vector3 distance = target.transform.position - transform.position; // Only change circle if we risk to lose the target. if (distance.magnitude > (_randomRadius - 0.2)) { DoCombatCircling(); } } }
// Update is called once per frame void Update() { // Increase harvest timer. _harvestTimer += Time.deltaTime; // Return to base if resource source depleted or inventory is full. if (!_currentSource || _inventory.IsFull()) { _pheromonePlacement.SetPheromoneType(EPheromoneTypes.Food); _states.currentState = EAntStates.ReturnToBase; return; } // Harvest some resources if possible (timer). if (_harvestTimer >= _harvestSpeed) { _navHelper.Stop(); _currentSource.DecrementCapacity(); _inventory.IncrementCapacity(); _harvestTimer = 0.0f; } }