public void Tick() { // if timer is active, increment time if (_timerActive) { _elapsedTime += Time.deltaTime; } // if our elapsed time has met our required duration, then go back to Idle if (_elapsedTime > _foundDelayDuration) { StopTimer(); _searchBotSM.ChangeState(_searchBotSM.IdleState); } }
public void FixedTick() { // instead of listening for the 'NewTarget' event, we can optionally just look at data belonging to the SM // this is useful if you have shared data that's important to multiple states... unit health, etc. float distanceFromTarget = Vector3.Distance(_searchBotSM.TargetPosition, _rb.position); // if we're close enough to the target, enter 'detect state if (distanceFromTarget < .1f) { _searchBotSM.ChangeState(_searchBotSM.FoundState); } // otherwise, keep moving else { RotateTowardsTarget(); MoveTowardsTarget(); } }
void OnNewTargetAcquired(Vector3 newPosition) { _searchBotSM.ChangeState(_searchBotSM.SearchState); }