Hide Cursor ONLY while InGame

I made a script and attached it to an empty gameobject in an InGame level scene, the script just says :

void Update ()
{
Cursor.visible = false;
}

But if i lose and i get thrown into the LoseScene (Which is a menu to restart level) I cannot see the cursor, even though the empty gameobject isnt in that scene, I really dont know why this is happening but, i supposed i could fix it by adding a variable or something like that so it says:

if (InGame == true)
{
 Cursor.visible = false;
}
else
{
Cursor.visible = true;
}

But obviously i have to make the variable mean something, how can i do that?

Because you misunderstood how that class variable works. Any class member - variable, property, function, etc - that is static is not bound to any instance of that class. This means that you can access that variable at any time without having to create an instance of the class. Additionally this means the variable is global for that class.

Simply put once you’ve set a static variable to one value it will retain that value for the entire program until changed again.

Since it retains it’s value you don’t need to set it every frame (worst case doing so will negatively affect performance).

One quick solution is to make the cursor visible just before changing scenes.