#Using static variables only to reset when switching back to main scene.

1 messages · Page 1 of 1 (latest)

red kite
#

So basically, in my main scene, i have a player object with this code:

public static int Points;

public static int OtherPoints;
void Start(){
Points = 0;
OtherPoints = 0;
}

and in another scene, I'm increasing OtherPoints, but when i switch back, everything is reset as per void Start(). How do i fix this?

bright path
#

what do you mean by "switch back"?

#

static variables aren't serialized, and will be reset on scene load/change and playmode start/exit

red kite
#

oh

#

so what do i do?

#

btw i was using SceneManager.LoadScene();

bright path
#

one way is to make your variables non-static, and have a Singleton/manager object that stores those vars

#

or you can check out DontDestroyOnLoad to preserve objects between scene change