- Home /
Call previous level, as for whatever it was
Hey guys
So lets say there is 5 scenes in the game, and I jumped from 1 to 4, then I set a trigger for the 4th scene to call the previous one (which is 1) but instead of calling the scene 1 it calls scene 3. Whatever scene it was before scene 4 is the one I want to show up. How can I fix that?
Application.LoadLevel(Application.loadedLevel-1);
Thank you for the help.
Not something I've needed to do, but it'll probably work:
Just before you make a call to LoadLevel, set a variable in another gameobject's script to whatever the current level is.
When you load the next level, you can then access the number of the previous level using the mechanism above. In order for this to work, you would need to maintain state between levels, see also http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html and http://answers.unity3d.com/questions/747603/how-does-dontdestroyonload-work-1.html
if you can open new scene each time and get back to the previous then you need stack. for instance, you are in 1, go to 4, then from 4 to 3 and now you want back to 4 and from 4 to 1. for this you need to store in a stack.
you can actually remember as many as you want and even store multiple times the same scene creating complex puzzles.
I will try to do that, but I'm not sure if it is going to work. Because the thing is, there is 3 levels that brings to level 4, and it is totally random, so what I wanted to do is lets say, If 1 is to 4, bring 4 to 1, if 2 is to 4 bring 4 to 2 and so on. So I will stack the info in a script and do dontdestroyonload and lets hope it will work. I will get back to you guys to put the results.
Your answer
Follow this Question
Related Questions
Extreme Beginner Scripting Question 2 Answers
How does Unity "read" JavaScript code? 3 Answers
Help With "Scripting" 1 Answer
Camera movement(I have no clue how to code) 0 Answers
how to disable a script component 1 Answer