I’m trying to find a way to switch back and forth between two different Scenes. I have my main Scene, which is where the player and enemies are running around, and then I have a second inventory Scene, which is just Gui elements. I’ve been experimenting with Application.LoadLevel and it’s variations, open a scene, but I can’t find a way to then switch back to the previous scene. Once I open the inventory scene, using LoadLevel() to reopen the main scene resets the main scene, instead of switching back to where it was. When I use LoadLevelAdditive() instead, it’s even worse. The inventory screen is overlaid on the main scene, which still continues playing. Then reloading the main scene duplicates another copy of the scene on top of itself.
Is there any way to load a scene without throwing out the current scene, and then “turning off” the new scene so that we go back to where we were in the first scene? Think of opening an inventory screen, which pauses the game, and then closing it lets you continue where you left off.
It sounds to me like your second scene, should just be a enclosed box in your current scene. Say, way below where it will never be seen. Then you just put a camera down there and swap to it when you want to use it.
I think I get what you’re saying. My second scene is just gui elements, so I could just have a component that overlays the gui on the main scene and enable it when the player views his inventory, but I also need to freeze my main scene so enemies don’t attack while you’re away, moving the mouse doesn’t turn the character around, etc. I’ve tried Time.timeScale = 0, but that doesn’t disable the player’s controls. There has to be a way to do high level stuff like pausing on an entire scene, right?
Theres no built in way to do this. But you could accomplish this with prefabs, Basically storing all of the scene on of the menu into a single prefab you instantiate and destroy when you need it.
Theres also no built in way to pause that i know of, Application pausing is done for things like the game going to sleep with multitasking on ios, so you wouldn’t be able to tie into OnApplicationPause.
This isnt the most ideal solution for pausing but if you implement a Pause or Resume function you could send a message to all game objects and implement it yourself where you need to like this:
static bool paused;
public static bool isPaused
{
get { return paused; }
set {
if( paused != value )
{
paused = value;
string message = paused ? "OnGamePause" : "OnGameResume";
foreach(GameObject o in FindObjectsOfType(typeof(GameObject)) o.SendMessage(message, SendMessageOption.DontRequireReciever);
}
}
}
then that way any script where you need to do something to pause or resume from pause you can just throw in a function named either OnGamePause or OnGameResume.