using UnityEngine; using UnityEngine.AI; namespace Ai { public class PanicEnemy : TargetingEnemy { [SerializeField] private float _idleTime; [SerializeField] private float _moveTime; [SerializeField] private float _walkRadius; private bool _idle = true; private float _currentTime; protected override void Init() { base.Init(); _currentTime = 0.0f; } public override void Proceed(Vector3 playerPosition) { if (Vector3.Distance(playerPosition, transform.position) > _visibilityDistance) return; if (_idle) { _currentTime += Time.deltaTime; if (_currentTime >= _idleTime) { _agent.SetDestination(GetRandomPosition()); _agent.isStopped = false; _idle = false; } } if (!_idle) { _currentTime += Time.deltaTime; if (_currentTime >= _idleTime + _moveTime) { _currentTime = _currentTime - _moveTime - _idleTime; _agent.isStopped = true; _idle = true; } } } private Vector3 GetRandomPosition() { var randomDirection = Random.insideUnitSphere * _walkRadius; randomDirection.y = 0; randomDirection += transform.position; NavMeshHit hit; NavMesh.SamplePosition(randomDirection, out hit, _walkRadius, 1); return hit.position; } } }