Why does this coroutine crash Unity?

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
	}

Managed to locate and fix the problem with the debugger. It turns out what I thought to be an error in my coroutine actually ended up to be a syntax error in the enemStats.AttackSpeed get method. [Accidentally returned the function name instead of the data type, possibly causing an infinite loop]

Thanks for the hasty response, @Commoble! :smiley:

I’ll definitely check the debugger first next time!