// Initialization
 void Start()
 {
     firstRun = true;
     currentControllerUISelection = ControllerUISelection.play;
     CurrentGameState             = GameState.MainMenu;
     gsm           = gameObject.GetComponent <GameStateManager>();
     redSlimebw    = (selectScreen.transform.GetChild(0).GetComponent <Image>().sprite);
     yellowSlimebw = (selectScreen.transform.GetChild(1).GetComponent <Image>().sprite);
     blueSlimebw   = (selectScreen.transform.GetChild(2).GetComponent <Image>().sprite);
     purpleSlimebw = (selectScreen.transform.GetChild(3).GetComponent <Image>().sprite);
 }
    void menuStateUpdate()
    {
        //if the current gamestate is main menu
        if (CurrentGameState == GameState.MainMenu)
        {
            if (mainScreenMesh.activeInHierarchy == false)
            {
                mainScreenMesh.SetActive(true);
            }
            //if up or down is pressed switch current selected UI
            if ((Input.GetKeyDown(KeyCode.DownArrow) || XCI.GetButtonDown(XboxButton.DPadDown, XboxController.First) || XCI.GetAxisRaw(XboxAxis.LeftStickY, XboxController.First) > 0 || XCI.GetAxisRaw(XboxAxis.LeftStickY, XboxController.First) < 0 || Input.GetKeyDown(KeyCode.UpArrow) || XCI.GetButtonDown(XboxButton.DPadUp, XboxController.First)) && axisInUse == false)
            {
                axisInUse = true;
                if (currentControllerUISelection == ControllerUISelection.play)
                {
                    currentControllerUISelection = ControllerUISelection.exit;
                    UICrowm.transform.position  += new Vector3(0, -2.5f, 0);
                }
                else if (currentControllerUISelection == ControllerUISelection.exit)
                {
                    UICrowm.transform.position  += new Vector3(0, 2.5f, 0);
                    currentControllerUISelection = ControllerUISelection.play;
                }
                //Debug.Log(axisInUse);
            }

            if (XCI.GetAxisRaw(XboxAxis.LeftStickY, XboxController.First) == 0)
            {
                axisInUse = false;
            }

            //current selected ui is highlighted
            if (currentControllerUISelection == ControllerUISelection.play)
            {
                mainMenu.transform.GetChild(1).GetComponent <Button>().Select();
            }
            if (currentControllerUISelection == ControllerUISelection.exit)
            {
                mainMenu.transform.GetChild(2).GetComponent <Button>().Select();
            }

            //if enter or a is pressed select current highlighted ui
            if (Input.GetKeyDown(KeyCode.KeypadEnter) || XCI.GetButtonDown(XboxButton.A, XboxController.First))
            {
                if (currentControllerUISelection == ControllerUISelection.play)
                {
                    mainStartButton();
                }
                if (currentControllerUISelection == ControllerUISelection.exit)
                {
                    mainQuitButton();
                }
            }
        }

        // If the current game state is the Main Menu and Y is pressed.
        if (CurrentGameState == GameState.MainMenu)
        {
            if (Input.GetKeyDown(KeyCode.Y) || XCI.GetButtonDown(XboxButton.Y))
            {
                // Disable elements from the Main Menu.
                GameObject.FindGameObjectWithTag("MenuSlimeText").GetComponent <MeshRenderer>().enabled   = false;
                GameObject.FindGameObjectWithTag("MenuRedSlime").GetComponent <MeshRenderer>().enabled    = false;
                GameObject.FindGameObjectWithTag("MenuBlueSlime").GetComponent <MeshRenderer>().enabled   = false;
                GameObject.FindGameObjectWithTag("MenuYellowSlime").GetComponent <MeshRenderer>().enabled = false;
                GameObject.FindGameObjectWithTag("MenuPurpleSlime").GetComponent <MeshRenderer>().enabled = false;
                GameObject.FindGameObjectWithTag("MenuCrownLeft").GetComponent <MeshRenderer>().enabled   = false;
                GameObject.FindGameObjectWithTag("MenuCrownRight").GetComponent <MeshRenderer>().enabled  = false;
                GameObject.FindGameObjectWithTag("mainMenu").GetComponent <Canvas>().enabled = false;
                // Set current state to Credits.
                CurrentGameState = GameState.Credits;
                // Enable Credits canvas.
                GameObject.FindGameObjectWithTag("creditsScreen").GetComponent <Canvas>().enabled = true;
            }
        }

        // If the current game state is the Credits Screen and B is pressed.
        if (CurrentGameState == GameState.Credits)
        {
            if (Input.GetKeyDown(KeyCode.Backspace) || XCI.GetButtonDown(XboxButton.B))
            {
                // Disable elements from the Credits.
                GameObject.FindGameObjectWithTag("creditsScreen").GetComponent <Canvas>().enabled = false;
                // Set current state to Main Menu.
                CurrentGameState = GameState.MainMenu;
                // Enable Main Menu elements.
                GameObject.FindGameObjectWithTag("mainMenu").GetComponent <Canvas>().enabled              = true;
                GameObject.FindGameObjectWithTag("MenuSlimeText").GetComponent <MeshRenderer>().enabled   = true;
                GameObject.FindGameObjectWithTag("MenuRedSlime").GetComponent <MeshRenderer>().enabled    = true;
                GameObject.FindGameObjectWithTag("MenuBlueSlime").GetComponent <MeshRenderer>().enabled   = true;
                GameObject.FindGameObjectWithTag("MenuYellowSlime").GetComponent <MeshRenderer>().enabled = true;
                GameObject.FindGameObjectWithTag("MenuPurpleSlime").GetComponent <MeshRenderer>().enabled = true;
                GameObject.FindGameObjectWithTag("MenuCrownLeft").GetComponent <MeshRenderer>().enabled   = true;
                GameObject.FindGameObjectWithTag("MenuCrownRight").GetComponent <MeshRenderer>().enabled  = true;
            }
        }

        //if current game state is playerselect and enter or a is pressed and and there is more then one player
        if (CurrentGameState == GameState.PlayerSelect)
        {
            if (mainScreenMesh.activeInHierarchy == true)
            {
                mainScreenMesh.SetActive(false);
            }

            if (Input.GetKeyDown(KeyCode.KeypadEnter) || XCI.GetButtonDown(XboxButton.Start, XboxController.First))
            {
                if (gsm.controllers.Count > 1)
                {
                    //start the game
                    selectStartButton();
                }
            }
        }
    }