I assume this code is being read as an infinite loop, but I cannot figure out why.
I want this code to run until a GameObject is destroyed which would trigger the GameObject enemyTarget to return as null, breaking the loop.
I’ve force quit and rebooted my project about 20 times with new attempts but it’s become clear to me that I’m missing something. Really looking for a second opinion here. This is the code.
StartCoroutine(“Attack”);
public IEnumerator Attack()
{
while (enemyTarget != null)
{
enemyTarget.GetComponent<EnemyStats>().health -= attackDamage; //do damage
yield return new WaitForSeconds(attackSpeed);
}
LocateTargets(); //return to searching for targets
yield return null;
}