You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
1.0 KiB

using UnityEngine;
namespace Ai
{
public class ChasingEnemy : TargetingEnemy
{
[SerializeField] private float _idleTime;
[SerializeField] private float _movingTime;
[SerializeField] private bool _updatePosition;
private float _currentIdle;
private float _currentMoving;
private Vector3 _movingPosition;
[SerializeField] private bool _idle;
public override void Proceed(Vector3 playerPosition)
{
if (Vector3.Distance(playerPosition, transform.position) > _visibilityDistance)
return;
if (_idle)
{
_currentIdle += Time.deltaTime;
if (_currentIdle >= _idleTime)
{
_currentIdle = 0;
_idle = false;
_movingPosition = playerPosition;
_agent.isStopped = false;
}
}
if (!_idle)
{
_agent.SetDestination(_updatePosition ? playerPosition : _movingPosition);
_currentMoving += Time.deltaTime;
if (_currentMoving >= _movingTime)
{
_currentMoving = 0;
_idle = true;
_movingPosition = Vector3.zero;
_agent.isStopped = true;
}
}
}
}
}