I dragged and dropped the TextMeshPro object from the hierarchy to the Inspector.
UpdateScore is called in another function. When I hit play, the zero appears for “Score:0”, so it “works”. but I also get the error message:
“NullReferenceException: Object reference not set to an instance of an object
GameManager.Start () (at Assets/_scripts/GameManager.cs:18)”
Line 18 is the first use of" " scoreText.text = “Score: " + score;” So this line works to put the zero in the on screen text but also throws the error message.
in UpdateScore the Debug,Log prints the correct score but the on screen text does not update and again the Null reference exception error is given.
How do I fix this?
Why is the first example working while throwing an error?
Thank you for your help.
Expect to see this error a LOT. It’s easily the most common thing to do when working. Learn how to fix it rapidly. It’s easy. See the above link for more tips.
This is the kind of mindset and thinking process you need to bring to this problem: