I’m making an FNaF fan game but I need some help somewhere. There is a “New Game”, “Continue” and “Extra” button. Next to the “Continue” button there is a counter showing what night we are in. There is a “NightCounter” script inside the GameObject named “Night System”. Inside that script is “public string Night;”. What I want: If I change the number “1” from the inspector menu you see in the picture, the counter in the game will also change.
Unity 2019.4.36f1 Personal
You’ll need to have a script on your continue night GameObject that has a reference to the NightCounter script. From there just set the TMP text to the value you need:
public NightCounter nightCounter; // Set this value in the inspector
// Put this in either Start or Update
GetComponent<TextMeshProUGUI>().text = nightCounter.nightCount.ToString(); // I can't see what the variable actually is, so update it accordingly.
If you want to see the change in real time in the Editor, add a [ExecuteAlways]
just before the class declaration in your script.
Hope this helps!
What can I write in Continue Night’s script so that “Continue Night” connects with “Night Counter”. I would be glad if you give more detailed information.
As long as there’s only ever one Night Counter in one scene, you can use FindFirstObjectOfType(typeof(NightCounter))
to obtain a reference to the Night System’s NightCounter script.
The other option is to use a public or serialized field in the Continue Night script (for example: public NightCounter nightCounter;
) and manually drag and drop the Night System GameObject on the field in the Inspector.