This seems to crash my game every time it is run, can’t figure out why. I’ve taken out the working code, but it’s supposed to attack the player every x seconds. [enemStats holds the variables for that]
private bool isAttackingPlayer;
void Update () {
if(!isAttackingPlayer)
attackPlayer ();
}
private void attackPlayer(){
// enemy is in range [Attack!]
StartCoroutine(attackingPlayer(enemStats.AttackSpeed));
// TODO start attack voice & animation
}
IEnumerator attackingPlayer(float waitTime){
isAttackingPlayer = true; // starting to attack
yield return new WaitForSeconds (waitTime); // wait after cd
// wait time ended
if (playerStats.ShieldHP >= 0) // if there is a shield up
playerStats.ShieldHP -= enemStats.Damage;
else
playerStats.PlayerHP -= enemStats.Damage;
isAttackingPlayer = false; // no longer attacking
}