#lets make a thread

1 messages · Page 1 of 1 (latest)

night ether
#
private bool canAttack=true;

else if (attackDistance >= distance && canAttack)
        {
            RandomlyChooseAttack();
        }

void CoolDown()
    {
        timer -= Time.deltaTime;

        if (timer < 0 && cooling && attackMode)
        {
            cooling = false;
            canAttack = true;
            timer = intTimer;
        }
    }

void StopAttack()
    {
        cooling = false;
        attackMode = false;
        anim.SetBool("DownSlash", false);
        anim.SetBool("SideSlash", false);
        anim.SetBool("UpSlash", false);
        canAttack = true;
    }
#

that should do it

#

so the logic is
to start with you can attack
once an attack has started you cannot attack again until the cooldown period is over or the attack is stopped

coarse thistle
#

I tried it. RandomlyChooseAttack is being called constantly and timer is not counting down after these changes

#

In the previous version of the code RandomlyChooseAttack is being called only when enemy attacks

#

This script is attached to enemy. It's enemy AI for a 2D platformer kind of game

night ether
#

do you still have the canAttack=false in RandomlyChooseAttack you need this

#

should not have canAttack=true in TriggerCooling

#

take it out