Пример #1
0
        // Use this for initialization
        void Start()
        {
            DontDestroyOnLoad(this);
            if (playerSpawns.Count < 1)
            {
                playerSpawns.Add(transform);
            }

            if (GameObject.FindGameObjectWithTag("Player"))
            {
                player = GameObject.FindGameObjectWithTag("Player");
            }

            if (!player)
            {
                player = Instantiate(playerPrefab);
                _ms    = player.GetComponent <PlayerRig>().menuSystem;
                player.GetComponent <PlayerRig>().SetGC(this);
                if (DEBUG_MODE)
                {
                    if (!player.GetComponent <PlayerRig>().DEBUG_MODE)
                    {
                        player.GetComponent <PlayerRig>().DEBUG_MODE = true;
                    }
                }
            }
            loadScene = false;
            pauseGame = false;
        }
Пример #2
0
        // Update is called once per frame
        void Update()
        {
            if (!_ms)
            {
                if (GameObject.FindGameObjectWithTag("MenuSystem"))
                {
                    _ms = GameObject.FindGameObjectWithTag("MenuSystem").GetComponent <MenuSystem>();
                }
            }
            else
            {
                switch (state)
                {
                case GameState.Active:
                    #region Active
                    // if the game is flagged to load a scene
                    if (loadScene)
                    {
                        StartLoadScene(sceneToLoad);
                    }
                    else
                    {
                        if (player)
                        {
                            if (!player.activeSelf)
                            {
                                player.SetActive(true);
                            }
                        }
                    }
#if (UNITY_EDITOR)
                    if (Input.GetButtonDown("Pause"))
                    {
                        state     = GameState.Paused;
                        pauseGame = true;
                    }
#else
                    if (Input.GetButtonDown("Cancel"))
                    {
                        LoadMe("MMscene01");
                    }
#endif
                    #endregion
                    break;

                case GameState.Loading:
                    #region Loading
                    // If the current scene is not the main menu scene
                    if (SceneManager.GetActiveScene().buildIndex > 0)
                    {
                        if (sceneReady)
                        {
                            state = GameState.Paused;
                        }
                    }
                    else
                    {
                        if (sceneReady)
                        {
                            state = GameState.Paused;
                        }
                    }
                    #endregion
                    break;

                case GameState.Paused:
                    #region Paused
                    // If the current scene is not the main menu scene
                    if (SceneManager.GetActiveScene().buildIndex > 0)
                    {
                        // If the screen is clear
                        if (_ms.ScreenClear)
                        {
                            // The game is flagged to be paused
                            if (pauseGame)
                            {
                                // Pause the game
                                PauseGame(true);
                                // If the player presses the pause button
                                if (Input.GetButtonDown("Pause"))
                                {
                                    // Flag to resume the game
                                    PauseGame(false);
                                }
                                // If the game is supposed to load a scene
                                if (loadScene)
                                {
                                    // Unpause the game
                                    PauseGame(false);
                                    // Load the specified scene
                                    StartLoadScene(sceneToLoad);
                                }
                            }
                            // If the game is not flagged to be paused (this is to catch the initial load-in from another scene)
                            else
                            {
                                // Set the state to active
                                state = GameState.Active;
                            }
                        }
                    }
                    // If it is the main menu scene
                    else
                    {
                        // If the screen is clear
                        if (_ms.ScreenClear)
                        {
                            // The game is flagged to be paused
                            if (pauseGame)
                            {
                                // If the player presses the pause button
                                if (Input.GetButtonDown("Pause"))
                                {
                                    // Flag to resume the game
                                    PauseGame(false);
                                }
                                // If the game is supposed to load a scene
                                if (loadScene)
                                {
                                    // Unpause the game
                                    PauseGame(false);
                                    // Load the specified scene
                                    StartLoadScene(sceneToLoad);
                                }
                            }
                            // If the game is not flagged to be paused (this is to catch the initial load-in from another scene)
                            else
                            {
                                // Set the state to active
                                state = GameState.Active;
                            }
                        }
                    }
                    #endregion
                    break;

                default:
                    break;
                }
            }

            Debug.Log("Game State: " + state.ToString());
        }