void Update() { //Debug.Log(_currentState); if (_lineOfSight.IsInSight) //&& _squirrel.isVisible()) { _currentState = BeetleStates.ChasingSquirrel; } else if (_currentState != BeetleStates.ChasingSound) { _currentState = BeetleStates.Patrolling; } switch (_currentState) { case BeetleStates.Patrolling: patrol(); break; case BeetleStates.ChasingSquirrel: chase(_lineOfSight.inSight.position); break; case BeetleStates.ChasingSound: chase(_soundToChasePosition); if (InRange(_soundToChasePosition, radiusOfSoundToChase)) { _currentState = BeetleStates.Patrolling; } break; } }
public void hearSound(Vector3 sourcePoint) { if (_currentState != BeetleStates.ChasingSquirrel && InRange(sourcePoint, radiusOfHearing)) { _soundToChasePosition = sourcePoint; _currentState = BeetleStates.ChasingSound; } }
void Awake() { _lineOfSight = GetComponent <LineOfSight>(); //_squirrel = (Squirrel3D)FindObjectOfType(typeof(Squirrel3D)); _lineOfSight.Target = _squirrel; _flocking = GetComponent <Flocking>(); _currentState = BeetleStates.Patrolling; _currentWaypoint = startPath; _flocking.Target = _currentWaypoint.transform.position; }