Unity Editors crashes after using a button in scene

Hi,

My Unity Editor(2019.4.11f1) keeps crashing after I use a button in my scene. Now I don’t know why but I’m pretty sure it has to do something with my Game Manager. I also tried using another version of the editor but I get the same problem. Here is my Game Manager Script:

{
    public TextMeshProUGUI CounterText;
    public TextMeshProUGUI scoreText;

    private int turn = 0;
    public static int score;
    public int scoreValue;

    public bool isGameActive;

    public GameObject titleScreen;
    public Button startbutton;

    private void Start()
    {
       
    }

    private void OnTriggerEnter(Collider other)
    {
        turn += 1;
        CounterText.text = "Turn : " + turn + "/3";

        score += scoreValue;
        scoreText.text = "score: " + score;
    }

    public void startGame()
    {
        isGameActive = true;
        score = 0;
        turn = 0;
        titleScreen.gameObject.SetActive(false);
    }
}

Here is the Game Manager’s inspector:
177953-game-manager.png

I’m making a title screen that i want to deactivate as soon as I click the start button, when I click the button the whole editor freezes. Can anyone make out what is causing that. I’ll add the script for my button as well just in case:

    private Button startButton;
    private GameManager gameManager;

    // Start is called before the first frame update
    void Start()
    {
        startButton = GetComponent<Button>();
        gameManager = GameObject.Find("Game Manager").GetComponent<GameManager>();

        startButton.onClick.AddListener(StartGameOnClick);
    }

    // Update is called once per frame
    void Update()
    {

    }
    void StartGameOnClick()
    {
        Debug.Log(" Game has started");
        gameManager.startGame();
    }

}

Does anybody have a clue of why this is happening? Thanks in advance!

There’s your problem:

void Update()
     { while (gameManager.isGameActive)
         { ...

You can’t use a while loop like this in your Update method because Unity runs on a single thread, which means it waits until the whole Update has finished executing before moving onto the next frame, and in this case gameManager.isGameActive stays true, and that Update() will never finish.

You are probably wanting to do this, instead:

 void Update()
     { if (gameManager.isGameActive)
         {

Check out the Unity log to find out what the problem is, you can find where it is here: