Ejemplo n.º 1
0
    /// <summary>
    /// Use this: SetGameState(Object.FindObjectOfType&lt;GameState&gt;());
    /// </summary>
    /// <param name="newSceneState"></param>
    public void SetGameState <T>() where T : SceneState
    {
        newSceneState = FindObjectOfType <T>();

        if (newSceneState == null)
        {
            Debug.LogError("The specified gamestate equals null!");
            return;
        }

        if (currentGameState == newSceneState)
        {
            Debug.LogWarning("You are trying to start the current gamestate again, aborted!");
            return;
        }

        if (currentGameState != null)
        {
            currentGameState.Disable();
        }

        this.currentGameState = newSceneState;

        if (OnStateChange != null)
        {
            OnStateChange();
        }

        //Application.LoadLevel(currentGameState.selectedScene); // Deprecation fix

        StartCoroutine(WaitForLevelToLoad());
    }