DontDestroyOnLoad object's reference order?

So, let’s say,
there are 2 scenes, s1, s2.
And there is [gm] gameObject script (GameManager).

and s1 has s1object and it has s1script attached, s2 scene has s2object and s2script.

And only [gm] has DontDestroyOnLoad.

Then, if I want to call some function of scene2 or change some vars in scene2 at the start of scene2 being loaded, how can I ?

if(Application.loadedLevel ==…) in [gm]'s update function?
or other more simple solution than not using update mechanic for better performance?

Thanks.

You could use OnLevelWasLoaded(int level) to determine when the level is loaded and then just use a boolean to check which level is loaded.

Example:

C#:

//By default Scene 1 is loaded
bool isScene1Loaded = true;

void Update()
{
    if(isScene1Loaded)
    {
         //Scene1 Code
    }
    else
    {
         //Scene2 Code
    }
}

//Called when a level is loaded
void OnLevelWasLoaded(int level)
{
   //if the level that was loaded is scene 2,
   //the given parameter is Zero-Based so,
   //0 equals scene1, 1 equals scene 2, ect.
   if(level == 1)
   {
        //Set isScene1Loaded to false
        //Since Scene1 is not loaded anymore
        isScene1Loaded = false;
    }
}

JS:

var isScene1Loaded : bool = true;

function Update()
{
    if(isScene1Loaded)
    {
         //Scene1 Code
    }
    else
    {
         //Scene2 Code
    }
}

function OnLevelWasLoaded(level : int)
{
    if(level == 1)
    {
        isScene1Loaded = false;
    }
}

Thanks!