Home > Back-end >  Unity How to active method in another scene?
Unity How to active method in another scene?

Time:04-04

I have a scene, that I am loading into from a menu. However I have two ways I want to load in, one just loading the scene which starts a brand new level. Another I want to load the scene but, then load in an XML file storing the players progress.

I have a method to load in the xml file, I just need to activate it when continue game button is pressed in another scene. Is there a way to do this without having to create two scenes one from new games and one for current game.

CodePudding user response:

You could use a class with static variables for say wheter you want to load or start a Game:

public class someClass
{
    public static bool continue = false;
}

Now from anywhere you can acess this by doing:

//put this in the script loading your scene
someClass.continue = true;
//load Scene

And in you loaded scene in some MonoBehaviour:

if (someClass.continue == true)
    //do sth. like loading XML or not
  • Related