P
private float timeAttack;
private void Start()
{
speed = defaultSpeed;
scanerRange = defaultScanerRange;
anim = GetComponent<Animator>();
StartCoroutine(BattleMode());
}
private void Update()
{
if(timeAttack > 0f)
{
timeAttack -= Time.deltaTime;
}
Debug.Log(timeAttack);
}
IEnumerator BattleMode()
{
while (true)
{
if (Vector2.Distance(Player.transform.position, transform.position) <= attackRange)
{
if (timeAttack <= 0f)
{
anim.SetTrigger("attack");
timeAttack = startTimeAttack;
}
}
yield return null;
}
}
Есть такой код из-за которого враг не может атаковать без перерыва, но в игре анимация атаки срабатывает дважды не смотря на то что timeAttack имеет значение больше 0f, с чего это так работает?