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

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.

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));
  }
}