Just stumbled across this thread. I would recommend a class named ApplicationModel in which you insert a static variable named “ending” or something like that. Static variables stay even if you change scenes.
You can access the attribute like this: ApplicationModel.ending
Example class with static attribute:
public class ApplicationModel
{
static public int ending = 0; // this is reachable from everywhere
}
A static variable can't be changed though. I suspect what he wants to do is change which ending is shown based on the actions of the player. In this case, static won't work.
Just like how @Ches81 pointed out you can use a static variable and access it every time. This is more secure.
Another way is by using PlayerPrefs. using PlayerPrefs, you can set values to variables and check those whenever you want. This is the easiest in my opinion, but might not be secure (unless you decide to use some kind of encryption techniques to encrypt the messages in playerprefs).
In your Game Script, use this when the level ends
PlayerPrefs.SetInt("Ending", 0);
In your Ending Script use this
int Ending = PlayerPrefs.GetInt(“Ending”);
if(Ending == 0){
//do what you want
}
else{
//alternate ending
}
this ^^^^^^^^^^^^^ is gold
– pointcacheA static variable can't be changed though. I suspect what he wants to do is change which ending is shown based on the actions of the player. In this case, static won't work.
– dtumoloI think you confused static with const, which indeed you cannot change. :)
– Ches81