Switch() problem [C#]

Hey everybody !
I’m making a game with an enemy spawner and a GameManager who work with a Switch statement.
I would like to disable my player and my enemy spawner in “case 2:” but my spawner and my player aren’t disabled … this is my script :

    void StateMachine()
    {
        switch (State)
        {
            case 0: // INTRO
                endCanvas.SetActive(false);
                playerShip.SetActive(true);
                break;
            case 1: // GAME
                mobSpawner.GetComponent<MobSpawner>().enabled = true;
                playerShip.SetActive(true);
                break;
            case 2: // END GAME
                Debug.Log("End game");
                mobSpawner.GetComponent<MobSpawner>().enabled = false;
                Debug.Log("MobSpawner disabled");
                playerShip.SetActive(false);
                Debug.Log("PlayerShip disabled");
                endCanvas.SetActive(true);
                text_Kills.text = "You killed " + kills + " enemies !";
                break;
        }

The canvas appear, the console say :
“End Game”

“MobSpawner disabled”

“PlayerShip disabled”

Someone can help me ?

Thank you,

Bye, xyHeat

EDIT :

the entire script :

public class GameManager : MonoBehaviour {

    public GameObject playerShip;
    public GameObject mobSpawner;
    public GameObject endCanvas;

    public Text text_Kills;

    public int State;
    public int kills;

    void Start()
    {
        State = 1;
        StateMachine();
    }

    void StateMachine()
    {
        switch (State)
        {
            case 0: // INTRO
                endCanvas.SetActive(false);
                playerShip.SetActive(true);
                break;
            case 1: // GAME
                mobSpawner.GetComponent<MobSpawner>().enabled = true;
                playerShip.SetActive(true);
                break;
            case 2: // END GAME
                Debug.Log("End game");
                mobSpawner.GetComponent<MobSpawner>().enabled = false;
                Debug.Log("MobSpawner disabled");
                playerShip.SetActive(false);
                Debug.Log("PlayerShip disabled");
                endCanvas.SetActive(true);
                text_Kills.text = "You killed " + kills + " enemies !";
                break;
        }
    }

    public void ToIntro()
    {
        State = 0;
        StateMachine();
    }

    public void ToGame()
    {
        State = 1;
        StateMachine();
    }

    public void ToEndGame()
    {
        State = 2;
        StateMachine();
    }
}

Make sure there aren’t any objects calling your methods. From your code, a way to quickly determine that would be to look at the endCanvas. If that gets enabled, but the others stay disabled, it means that something else is re-enabling your scripts.

Also i would make the StateMachine method have an int or enum as a parameter, so you don’t have a global variable. Just call StateMachine (2) or if you use enums StateMachine(GameStates.Intro) or something similar.