I am trying to make a timed attack system. it needs to start the timer when an enemy is acquired…but there is a bug…as soon as the next enemy is killed it quickly starts the timer and attacks twice in a short period of time…here is the code: (AttackWait is the timer that says canAttack is true after a “waitForSeconds” command), and enemyObject is the gameObject that tells the script which object to attack…Any ideas on how to solve this?
if(enemyObject == null)
{
canAttack = false;
canCheckEnemy = true;
}
if(enemyObject != null && canAttack == false && canCheckEnemy == true)
{
AttackWait();
canCheckEnemy = false;
}
//if there is an enemy...attack it
if(enemyObject != null && canAttack == true)
{
canAttack = false;
Attack();
}