- Home /
Detect the previous level?
Ok I have level1 and level2. In level2 I have an object that is destroyed if you loaded from level1 to level2, but if you load level2 straight away, it's not destroyed.
What I can't figure out is how to detect if it was loaded from level1 or another level?
for example
level1 -to- level2 = destroy
level3 -to- level2 = don't destroy
Hopefully this explains what I want
Answer by Uzquiano · Apr 20, 2011 at 05:57 PM
Hi,
Just a solution, keep in an static varible the previous level (or a boolean to check if it went through level 1). But be sure it does not tget destroy when loading the next level.
Answer by GameGuy · Apr 20, 2011 at 07:12 PM
Try this little script. The only thing you need to do, look in Build Settings for the right number(zero counts too,if index shows 2 it need to be 3 and so on) of your scene an fill it into the variable currentLevel in Inspector.
var currentLevel : int = 0;
//
function OnGUI ()
{
if (GUI.Button (Rect (10,10,150,100), "Load Scene"))
{
Application.LoadLevel(currentLevel -(Application.levelCount-1));
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613124049im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
cover flow level select help please 0 Answers
What is the code for detecting a collision? 1 Answer
Puzzle Box Level Complete - Help Needed! 2 Answers
Video showing in the new level 0 Answers