private void OnEnable()
    {
        for (int i = 0; i < 4; i++)
        {
            GameDataMonobehaviour.instance.SetPlayerJoined(i, false);
        }

        if (player != 0)
        {
            joinScreen.SetActive(true);
        }
        else
        {
            isSelected = CharacterSelectStates.Selecting;
        }
    }
    void Update()
    {
        if (_HeartZoomTransition.enabled)
        {
            if (currentCharSelectState == CharacterSelectStates.LoadMainScene)
            {
                moveSprites();
            }

            return;
        }

        for (int i = 0; i < MAX_PLAYER_COUNT; i++)
        {
            if ((InputMapper.GrabVal(XBOX360_BUTTONS.B, i + 1) || Input.GetKeyDown(KeyCode.Backspace)) && CanGoBackToInstructions() && !wasBButtonPressed[i])
            {
                goBackScript.GoBackToInstructions();
                soundManager.SOUND_MAN.playSound("Play_MenuDown", gameObject);
            }

        }

        #if !UNITY_EDITOR && !UNITY_WEBGL && !UNITY_WEBPLAYER
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            _HeartZoomTransition.enabled = true;
            _HeartZoomTransition.StartHeartZoomIn(-1);
        }
        #endif

        switch ((int)currentCharSelectState)
        {
            case (int)CharacterSelectStates.WaitingForPlayers:
                updateButtonDownArrays();
                updateAnalogStickArray();

                if (playerCount >= MIN_PLAYER_COUNT_TO_START)
                {
                    for (int i = 0; i < isPlayerReadyArray.Length; i++)
                    {
                        if (isPlayerReadyArray[i])
                        {
                            if (InputMapper.GrabVal(XBOX360_BUTTONS.X, i + 1) && CanStartGame())
                            {
                                startGame();
                                soundManager.SOUND_MAN.playSound("Play_MenuConfirm", gameObject);
                                return;
                            }
                        }
                    }

                    if (Input.GetButtonDown("Meow_Button") && CanStartGame())
                    {
                        if (catModeIndex < CatModeLetters.Length)
                        {
                            CatModeLetters[catModeIndex].GetComponent<Text>().color = Color.black;
                            CatModeLetters[catModeIndex].GetComponent<UIFlasher>().SetDefaultColor(Color.black);
                        }

                        ++catModeIndex;

                        if (catModeIndex >= CatModeLetters.Length)
                        {
                            catMode = true;
                            catModeBackground.SetActive(true);
                            regularBackground.SetActive(false);
                            startGame();
                            soundManager.SOUND_MAN.playSound("Play_MenuConfirm", gameObject);
                        }
                    }
                }
                CheckForPlayerStateChanges();

        #region Debug Code
        #if UNITY_EDITOR || UNITY_WEBGL || UNITY_STANDALONE
                if (playerCount >= MIN_PLAYER_COUNT_TO_START)
                {
                    if (Input.GetKeyDown(KeyCode.Space) && CanStartGame())
                    {
                        startGame();
                        soundManager.SOUND_MAN.playSound("Play_MenuConfirm", gameObject);
                    }
                    else if (CanStartGame())
                    {
                        switch (catModeIndex)
                        {
                            case 0:
                                if (Input.GetKeyDown(KeyCode.M))
                                {
                                    CatModeLetters[catModeIndex].GetComponent<Text>().color = Color.black;
                                    CatModeLetters[catModeIndex].GetComponent<UIFlasher>().SetDefaultColor(Color.black);
                                    ++catModeIndex;
                                }
                                break;
                            case 1:
                                if (Input.GetKeyDown(KeyCode.E))
                                {
                                    CatModeLetters[catModeIndex].GetComponent<Text>().color = Color.black;
                                    CatModeLetters[catModeIndex].GetComponent<UIFlasher>().SetDefaultColor(Color.black);
                                    ++catModeIndex;
                                }
                                break;
                            case 2:
                                if (Input.GetKeyDown(KeyCode.O))
                                {
                                    CatModeLetters[catModeIndex].GetComponent<Text>().color = Color.black;
                                    CatModeLetters[catModeIndex].GetComponent<UIFlasher>().SetDefaultColor(Color.black);
                                    ++catModeIndex;
                                }
                                break;
                            case 3:
                                if (Input.GetKeyDown(KeyCode.W))
                                {
                                    CatModeLetters[catModeIndex].GetComponent<Text>().color = Color.black;
                                    CatModeLetters[catModeIndex].GetComponent<UIFlasher>().SetDefaultColor(Color.black);
                                    ++catModeIndex;

                                    catMode = true;
                                    catModeBackground.SetActive(true);
                                    regularBackground.SetActive(false);
                                    startGame();
                                    soundManager.SOUND_MAN.playSound("Play_MenuConfirm", gameObject);
                                }
                                break;
                        }
                    }
                }

                KeysCheckIfPlayerReady();
        #endif
        #endregion
                break;

            case (int)CharacterSelectStates.SelectingGhost:
                if (GhostSelectionDuration > 0)
                {
                    GhostSelectionDuration -= Time.deltaTime;
                    timeSinceGhostSelectingStart += Time.deltaTime;

                    if (GhostSelectionDuration < maxTimeBetweenGhostSelector)
                    {
                        setFinalGhostSelectorImage();
                    }
                    else if (timeToNextGhostSelector > 0)
                    {
                        timeToNextGhostSelector -= Time.deltaTime;
                    }
                    else
                    {
                        setNextGhostSelectorImage();
                        soundManager.SOUND_MAN.playSound("Play_MenuDown", gameObject);
                        timeToNextGhostSelector = easeInCubic(timeSinceGhostSelectingStart, initialTimeToNextGhostSelector, maxTimeBetweenGhostSelector, maxGhostSelectionDuration);
                    }
                }
                else
                {
                    CharSelectState = CharacterSelectStates.GhostRevealed;
                }
                break;

            case (int)CharacterSelectStates.GhostRevealed:
                if (GhostRevealDuration > 0)
                {
                    GhostRevealDuration -= Time.deltaTime;
                }
                else
                {
                    CharSelectState = CharacterSelectStates.Panic;
                }
                break;

            case (int)CharacterSelectStates.Panic:
                if (PanicDuration > 0)
                {
                    PanicDuration -= Time.deltaTime;
                }
                else
                {
                    CharSelectState = CharacterSelectStates.RunFromGhost;
                }
                break;

            case (int)CharacterSelectStates.RunFromGhost:
            case (int)CharacterSelectStates.LoadMainScene:
                if (RunFromGhostDuration > 0)
                {
                    RunFromGhostDuration -= Time.deltaTime;
                }
                else
                {
                    CharSelectState = CharacterSelectStates.LoadMainScene;
                }

                moveSprites();
                break;
        }
    }
 private void startGame()
 {
     Debug.Log("Starting game...");
     FillStartSpriteArray();
     CharSelectState = CharacterSelectStates.SelectingGhost;
 }
    void Update()
    {
        if (_HeartZoomTransition.enabled)
        {
            return;
        }

        if ((InputMapper.GrabVal(XBOX360_BUTTONS.B, 1) || Input.GetKeyDown(KeyCode.Backspace)) && CanGoBackToInstructions() && !wasBButtonPressed[0])
        {
            goBackScript.GoBackToInstructions();
            soundManager.SOUND_MAN.playSound("Play_MenuDown", gameObject);
        }

        #if !UNITY_EDITOR && !UNITY_WEBGL && !UNITY_WEBPLAYER
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            _HeartZoomTransition.enabled = true;
            _HeartZoomTransition.StartHeartZoomIn(-1);
        }
        #endif

        switch ((int)currentCharSelectState)
        {
            case (int)CharacterSelectStates.WaitingForPlayers:
                updateButtonDownArrays();
                updateAnalogStickArray();

                if (playerCount >= MIN_PLAYER_COUNT_TO_START)
                {
                    for (int i = 0; i < isPlayerReadyArray.Length; i++)
                    {
                        if (isPlayerReadyArray[i] && InputMapper.GrabVal(XBOX360_BUTTONS.X, i + 1))
                        {
                            if (CanStartGame())
                            {
                                startGame();
                                soundManager.SOUND_MAN.playSound("Play_MenuConfirm", gameObject);
                            }
                        }
                    }
                }
                CheckForPlayerStateChanges();

                #region Debug Code
        #if UNITY_EDITOR || UNITY_WEBGL || UNITY_STANDALONE
                if (Input.GetKeyDown(KeyCode.Space) && playerCount >= MIN_PLAYER_COUNT_TO_START)
                {
                    if (CanStartGame())
                    {
                        startGame();
                        soundManager.SOUND_MAN.playSound("Play_MenuConfirm", gameObject);
                    }
                }

                KeysCheckIfPlayerReady();
        #endif
                #endregion
                break;

            case (int)CharacterSelectStates.LoadMainScene:
                CharSelectState = CharacterSelectStates.LoadMainScene;
                break;
        }
    }
 private void startGame()
 {
     Debug.Log("Starting game...");
     FillStartSpriteArray();
     CharSelectState = CharacterSelectStates.LoadMainScene;
 }
    // Update is called once per frame
    void Update()
    {
        if (device == null || !device.active)
        {
            return;
        }

        bool pressingLeft  = device.LeftStick.Left.IsPressed || device.DPadLeft.IsPressed;
        bool pressingRight = device.LeftStick.Right.IsPressed || device.DPadRight.IsPressed;
        bool select        = device.Action1.WasPressed;
        bool cancel        = device.Action2.WasPressed;

        if (isSelected != CharacterSelectStates.NotJoined)
        {
            if (lastSelectionTime + selectionDelay < Time.time && isSelected == CharacterSelectStates.Selecting)
            {
                if (pressingLeft)
                {
                    SelectLeft();
                    lastSelectionTime = Time.time;
                }
                else if (pressingRight)
                {
                    SelectRight();
                    lastSelectionTime = Time.time;
                }
            }

            if (cancel && isSelected == CharacterSelectStates.Selecting && player == 0)
            {
                mainMenu.OpenMainMenuScreen();
            }
            else if (cancel && isSelected == CharacterSelectStates.Selecting)
            {
                isSelected = CharacterSelectStates.NotJoined;
                joinScreen.SetActive(true);
            }

            if (select && isSelected == CharacterSelectStates.Selected && player == 0)
            {
                mainMenu.StartLevelSelectScreen();
            }

            if (select && isSelected == CharacterSelectStates.Selecting)
            {
                //gameDataDefinition.SetCharacter((int)player, activeDefinition);
                GameDataMonobehaviour.instance.SetPlayerJoined((int)player, true);
                isSelected = CharacterSelectStates.Selected;
                animationController.SetTrigger("OnAccept");
            }
            else if (cancel && isSelected == CharacterSelectStates.Selected)
            {
                GameDataMonobehaviour.instance.SetPlayerJoined((int)player, false);
                isSelected = CharacterSelectStates.Selecting;
                animationController.SetTrigger("OnCancel");
            }
        }
        else
        {
            if (select)
            {
                isSelected = CharacterSelectStates.Selecting;
                joinScreen.SetActive(false);
            }
        }
    }