- Home /
Load Scene from intermediary Scene
This may be a basic question but I am unable to find any help on it anywhere,
For a VR project i'm working on the user must return to location (0,0) befroe the next level, so I have a intermediate scene for the user to move back to freely, then when ready press a button to load the next scene.
For this I need to be able to load the next scene, but do I need to have a separate intermediate level for each scene, e.g Scene 1 to 2, Scene 2 to 3?
No, I have tried with controller input, for example when the user clicks the player can switch screens, is it easier with an object?
Answer by Chik3r · Mar 04, 2018 at 06:15 PM
Using a scriptable object:
Create a script called SceneIndexObject.
Add this code:
using UnityEngine; [CreateAssetMenu(fileName = "SceneIndexObject")] public class SceneIndexObject : ScriptableObject { public int sceneIndex = 0; }
Go to your project, right click and select Create>SceneIndexObject
Now, before going to the "level loading" scene save in the object you created the "scene index" of the next level to load, and when you press the button to go to the next level, just load the scene that is in the object you created. More detail:
Have the script with a reference to the object:
public SceneIndexObject sceneIndexObj;
Drag the object you created to the inspector.
Access the "sceneIndex" variable and load that scene, also save the next scene in that variable.