Hi all hope your all ok today.
I working on a 2d shooter and i have run into a problem. my enemy is supposed to fire ten shots with a one second delay but is currently firing all ten shots without delay heres the code:
//fire project should shoot one bullet per second untill ten shots are shot
IEnumerator FireProjectile()
{
//output to console that we are fireing
Debug.Log("we should be shooting now!");
//delay before fireing first projectile
yield return new WaitForSeconds(0.5f);
while (EnemyAmmo < 10)
{
//fire projectile
Vector3 position = new Vector3(transform.position.x, transform.position.y - (transform.localScale.y / 2));
Instantiate(ProjectilePrefab, position, Quaternion.identity);
//update Enemy ammo to reflect that we have fired
EnemyAmmo++;
//output to console the current state of Enemy ammo
Debug.Log("remaining enemy ammo " + S_Enemy.EnemyAmmo.ToString());
yield return new WaitForSeconds(50.0f);
}
if (EnemyAmmo >= 10)
{
//output to the console that our clip should be empty
Debug.Log("Enemy clip spent!");
}
}
have i missed somthing are while loops ok for use with unity please provide feedback
361347–12544–$test_154.rar (1.87 MB)