Editor Freezes on Play

While prototyping I came up with an issue. When I try to use a coroutine (also tried it while) Unity crashes. The cause is infinite loop, however as you will understand from the code it is something intended:

    public GameObject[] enemies;
    //Game Manager
    public GameManager gameManager;

    //Frequency
    int counterMax = 45;
    int count = 0;

	// Use this for initialization
	void Start ()
    {
	}
	
    void Update()
    {
        //If playing
        if (gameManager.isPlaying)
        {
            //Increase the count
            count += 1;
            //When count reaches the max count
            if(count == counterMax)
            {
                //Spawn the enemy
                Spawn();
                //Reset the counter
                count = 0;
            }
        }
    }

    void Spawn()
    {
        //While playing
        while (gameManager.isPlaying)
        {
            //Pic a random enemy
            int i = Random.Range(0, enemies.Length);
            //INstantiate the enemy
            Instantiate(enemies*, transform.position, Quaternion.identity);*

}
}
This is the latest code I tried, the idea is to set isPlaying false when game ends. Am I missing a point?

Err, you’re not using a coroutine, so the while in Spawn() is creating an infinite loop on the main thread. You need to run Spawn as a coroutine and yield from it after each Instantiate.

i think the problem is there is a while loop in that Spawn Function and that is being called in your Update function. From my experiences, putting loops in the update function causes unity to bug out and freeze