Esempio n. 1
0
        /// <summary>
        /// Save the game and load the next scene when collider trigger entered by the player.
        /// </summary>
        /// <param name="other">Collider that has entered the trigger.</param>
        void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.tag.Equals("Player"))
            {     // only player can trigger
                if (SceneToLoad != "")
                { // fail safe
                    // spawn all
                    if (SpawnOnEnter.Count > 0)
                    {
                        StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnOnEnter, SpawnDelay, NoneSequentialSpawns, transform, null, 0, false, SpawnTarget.Any));  // trigger all spawns the the array
                    }

                    // save to data layer
                    LevelingSystem = other.gameObject.GetComponent <CharacterBase>();
                    if (!LevelingSystem)
                    {  // not found?
                        if (GlobalFuncs.DEBUGGING_MESSAGES)
                        {
                            Debug.Log("Leveling system not found on player");
                        }
                    }
                    else
                    {  // all good
                       // save the game
                        LevelingSystem.LastSaveGameID = GlobalFuncs.TheDatabase().SavePlayerState(ref LevelingSystem, SceneToLoad, -1);
                        MainMenu MainMenuSystem = GlobalFuncs.TheMainMenu();
                        if (MainMenuSystem)
                        {
                            MainMenuSystem.LatestSaveGameID = LevelingSystem.LastSaveGameID;

                            // confirm save to user
                            MainMenuSystem.SaveGameMessage.CrossFadeAlpha(1f, 0.01f, true);
                            MainMenuSystem.SaveGameMessage.text = "Save Complete..";
                            MainMenuSystem.SaveGameMessage.CrossFadeAlpha(0f, 3f, true);

                            // load the next scene
                            MainMenu_FadingLoad Fader = MainMenuSystem.gameObject.GetComponent <MainMenu_FadingLoad>();
                            if (Fader)
                            {
                                Fader.BeginFade(1);
                                Fader.LoadSceneAsync(SceneToLoad, LoadDelay);  // start the load with progress bar
                            }
                            else
                            {
                                if (GlobalFuncs.DEBUGGING_MESSAGES)
                                {
                                    Debug.Log("Main menu system NOT found in scene");
                                }
                            }
                        }
                        else
                        {
                            if (GlobalFuncs.DEBUGGING_MESSAGES)
                            {
                                Debug.Log("Main menu system NOT found in scene");
                            }
                        }
                    }
                }
                else
                {
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("Scene to load is NOT set");
                    }
                }
            }
        }