Unity Ver 2019 - Can't get Score Text to update on other levels

I cannot get the game score to update screen to screen. I have been through the video multiple times but can’t find out where I went wrong. (Though he didn’t demonstrate in the video more than one level.)
I verified that if I made a change to one GameStatus prefab, and then clicked on Overrides > Apply all, the change carried through to all other prefabs in other scenes.

In GameStatus.cs I made the State variable currentScore static instead of [SerializeField].

static int currentScore = 0;

This fixed it but I’m wondering why it worked in his video the other way?

Hi,

Maybe there are multiple GameStatus objects in your scene?

Nevermind, it looks like he is addressing this in the next lesson. :slight_smile: Though I am wondering why we just couldn’t use a static variable? (I haven’t finished video on Singleton yet so this may be answered in it later…)

static variables do not get exposed in the Inspector. Furthermore, we try to avoid static fields because all objects of the same class could manipulate the value, which can make debugging fairly inconvenient.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms