コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
 void OnNewTargetAcquired(Vector3 newPosition)
 {
     _searchBotSM.ChangeState(_searchBotSM.SearchState);
 }