hei.
insteed of stopping after one attack my animation plays through the whole Time between attacks time (i call it attackspeed in my code here) i followd the code and everything else is working. any idea why this is happening?
link to video:
and my fighter code
public class Fighter : MonoBehaviour, IAction
{
private Transform _target;
private ActionScheduler _actionScheduler;
private Mover _mover;
private Animator _animator;
private float timeSinceLastAttack;
public float weponRange=2;
public float attackSpeed = 3;
private void Start()
{
_mover = GetComponent<Mover>();
_actionScheduler = GetComponent<ActionScheduler>();
_animator = GetComponent<Animator>();
}
private void Update()
{
{
timeSinceLastAttack += Time.deltaTime;
//print(timeSinceLastAttack);
if (_target==null) return;
if (Vector3.Distance(transform.position,_target.transform.position)>weponRange)
{
_mover.MoveTo(_target.position);
}
else
{
_mover.Cancel();
AttackBehaviour();
}
}
}
//public void Move()
public void AttackBehaviour()
{
if (timeSinceLastAttack>attackSpeed)
{
_animator.SetTrigger("attack");
print("trigger");
timeSinceLastAttack = 0;
}
}
public void Hit()
{
}
public void Attack(CombatTraget combatTraget)
{
_actionScheduler.StartAction(this);
_target = combatTraget.transform;
}
public void Cancel()
{
_target=null;
}
}
}```