public bool PerformTransition(ScreenStateType targetState)
        {
            //Debug.Log("Next screen: " + targetState);

            if (!CurrentScreenState.CheckTransition(targetState))
            {
                Debug.LogWarning(targetState +
                                 " is currently not a valid state.");
                return(false);
            }

            bool result = false;

            ScreenStateBase state = GetStateByType(targetState);

            if (state != null)
            {
                // The pause state if it is currently active
                ScreenState_Pause pauseState =
                    CurrentScreenState as ScreenState_Pause;

                // Time continues if the pause state is exited
                // to something else than settings menu state
                if (pauseState != null &&
                    targetState != ScreenStateType.SettingsMenu)
                {
                    pauseState.ResumeGame();
                }

                SetState(CurrentScreenState, state);
                result = true;
            }
            else
            {
                Debug.LogError(targetState + " screen object is missing.");
            }

            return(result);
        }
        private void SetState(StateBase currentState, StateBase newState)
        {
            ScreenStateBase screenState = newState
                                          as ScreenStateBase;
            GameModeStateBase gameModeState = newState
                                              as GameModeStateBase;

            if (currentState != null)
            {
                currentState.Deactivate();
            }

            if (screenState != null)
            {
                //CurrentScreenState.Deactivate();
                CurrentScreenState = screenState;
                CurrentScreenState.Activate();

                if (ScreenStateChanged != null)
                {
                    ScreenStateChanged(screenState.State);
                }

                // Debugging
                _screen = CurrentScreenState.State;
            }
            else if (gameModeState != null)
            {
                //CurrentGameModeState.Deactivate();
                CurrentGameModeState = gameModeState;
                CurrentGameModeState.Activate();

                // Debugging
                _gameMode = CurrentGameModeState.State;
            }

            //Debug.Log("Changed from " + currentState + " to " + newState);
        }