How to see what level is running?

Hello,

I have a gameobject that exists on many levels.
I want to do an action of it when it’s on a certain level.

How I check this?

I tried this but t doesn’t work

if(Application.loadedLevel == 2)
{

}

Application.loadedLevel returns the index of the last loaded scene. Check your build settings to see if the indexes match, or use Application.loadedLevelName instead, which returns a string.

I solved it.

I used

function OnLevelWasLoaded (level : int) {
	if(level == 2)
	{
	
	}
}

OnLevelWasLoaded