I’ve stored scene objects like this UnityEngine.Object[] Scenes;
but Application.LoadLevel() take int or levelName … So is there any other way to load level using scene objects??
I’ve stored scene objects like this UnityEngine.Object[] Scenes;
but Application.LoadLevel() take int or levelName … So is there any other way to load level using scene objects??
You can simply place a script on said object with your LoadLevel call and the activating logic.
Application.loadLevel() uses Unity Scenes (.unity files). These are different from objects or gameObjects – a Unity Scene contains multiple gameObjects. Therefore, you have two choices. First, if you don’t absolutely have to use your UnityEngine.Object scenes array, you can just put each scene object in a different .unity file (Unity scene). The other option is to create prefabs from each of your objects. Then, write a script which instantiates these prefabs. Keep track of which prefab is instantiated and, when you instantiate a new one, destroy the old one. Here’s some sample code (c#):
public GameObject[] scenes; //The different scenes. Load these as prefabs in the inspector.
private GameObject instantiated = null; //Keep track of the instantiated prefab.
void instantiate(int n){
if(instantiated != null) GameObject.Destroy(instantiated); //Destroy the old scene.
instantiated = GameObject.Instantiate(scenes[n]); //Instantiate the new scene.
}
Apologies if this is slightly inaccurate, but it gets the concept across.