My new script crashes Unity

Hi there!

So, my new script called “EnemyAIAttack” completly crashes Unity whenever I try to run the scene with the enemy with that script. It should shoot the player with 3 shot bursts after getting to a nav point. Its activated by another script, called “EnemyAI”, that moves the enemy form his starting posistion to the nav point.

Here’s how those scripts look:`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyAI : MonoBehaviour {

UnityEngine.AI.NavMeshAgent nav;  
public Transform navTarget;
public Transform playerEyes;
public bool moving;

public EnemyAIAttack attack;

void Awake ()
{
	nav = GetComponent <UnityEngine.AI.NavMeshAgent> ();
	attack = GetComponent <EnemyAIAttack> ();
}

// Update is called once per frame
void Update () {
	Vector3 lookingPostition = new Vector3( playerEyes.transform.position.x, gameObject.transform.position.y, playerEyes.transform.position.z ) ;

	if (moving) {
		nav.enabled = true;
		nav.SetDestination (navTarget.transform.position);
		attack.shootThatBasterd = false;

	} else {
		nav.enabled = false;
		transform.LookAt(lookingPostition);
		attack.shootThatBasterd = true;
	}
}

}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyAIAttack : MonoBehaviour {

	public GameObject bulletPrefab;
	public Transform bulletSpawner;
	public float startWait;
	public int bulletCount;
	public float shootWait;
	public float bulletWait;

	public bool shootThatBasterd;

	// Use this for initialization
	void Start () {
		shootThatBasterd = false;
		StartCoroutine (SpawnWaves ());
	}

	IEnumerator SpawnWaves ()
	{
		yield return new WaitForSeconds (startWait);
		while (true) {
			if (shootThatBasterd) {
				for (int i = 0; i < bulletCount; i++) {
					GameObject g = (GameObject)Instantiate (bulletPrefab, bulletSpawner.position, bulletSpawner.rotation);
					yield return new WaitForSeconds (shootWait);

					float force = g.GetComponent<Rocket> ().speed;
					g.GetComponent<Rigidbody> ().AddForce (g.transform.forward * force);
				}
				yield return new WaitForSeconds (bulletWait);

				if (!shootThatBasterd) {
					break;
				}
			}
		}
	}
}

I will try to resolve this myself.

Waiting for help…

Try :

    while (true) {
         if (shootThatBasterd) {
             for (int i = 0; i < bulletCount; i++) {
                 GameObject g = (GameObject)Instantiate (bulletPrefab, bulletSpawner.position, bulletSpawner.rotation);
                 yield return new WaitForSeconds (shootWait);

                 float force = g.GetComponent<Rocket> ().speed;
                 g.GetComponent<Rigidbody> ().AddForce (g.transform.forward * force);
             }
             yield return new WaitForSeconds (bulletWait);

             if (!shootThatBasterd) {
                 break;
             }
         }
         yield return null ; // Wait one frame
     }