Game manager state isn't working

using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class GameManger : MonoBehaviour
{


    public GameObject playButton;
    public GameObject playerShip;
    public GameObject enemySpawner;
    public GameObject enemySpawner2;
    public GameObject deathMenu;

    private ScoreManager theScoreManager;

    public enum GameManagerState
    {
        Opening,
        Gameplay,
        GameOver,
        Restart,
    }

    GameManagerState GMState;

    void Start ()
    {
        GMState = GameManagerState.Opening;

        theScoreManager = FindObjectOfType<ScoreManager> ();

    }

    void UpdateGameManagerState()
    {
        switch (GMState)
        {
        case GameManagerState.Opening:


            playButton.SetActive (true);

            break;

        case GameManagerState.Gameplay:


            playButton.SetActive (false);

            playerShip.GetComponent<PlayerControl> ().Init ();

            enemySpawner.GetComponent<EnemySpawner> ().ScheduleEnemySpawner ();


            theScoreManager.scoreIncreasing = true;

            break;

        case GameManagerState.GameOver:

            enemySpawner.GetComponent<EnemySpawner> ().UnscheduleEnemySpawner ();

            deathMenu.SetActive (true);
            theScoreManager.scoreIncreasing = false;
            theScoreManager.scoreCount = 0;
            Invoke("ChangeToOpeningState", 4f);

            break;

        }
    }
      


    public void SetGameManagerState(GameManagerState state)
    {
        GMState = state;
        UpdateGameManagerState ();
    }

    public void StartGamePlay()
    {
        GMState = GameManagerState.Gameplay;
        UpdateGameManagerState ();
          
    }

    public void ChangeToOpeningState()
    {
        SetGameManagerState (GameManagerState.Opening);
    }
}

Everything that is stated to happen in Game state “GameOver”, doesn’t execute, such as the enemy spawner stopping and the score to stop increasing. Whats causing this? The only thing that executes correctly would be the enemy spawner starting, it actually starts when i click the play button. I am an extreme newbie around this stuff, so give me a bit of slack.

When/where do you call SetGameManagerState(GameManagerState.GameOver)?

Line 60?

Line 60 is the code that operates when the state is GameOver and UpdateGameManagerState() is called… but you need to change the state and call UpdateGameManagerState, which is what ‘SetGameManagerState’ does.

So, where are you calling SetGameManagerState(GameManagerState.GameOver)?

If nowhere, that’s why that code never runs… you never call it.

By the sounds of you are better than me lmao, how would i call it in?

Sorry for late response, was trying to figure how to do it by myself…Cannot seem to figure it out, where/how would i call it?

That’s honestly up to you.

You’d call that function on some event that is GameOver.

Not sure what constitutes game over in your game… really depends on your game in general. Like if you have a avatar/player that when shot dies, and if died too many times, GameOver… you’d have in the script that listens for the death signal a game over when said conditions are met.

Where as if it was like a Tetris game, it’d be when the puzzle area fills up. You’d have a script monitoring that, and when the condition is met, you call for a game over.