- Home /
Score text overlapping
Hi Guys!
I'm currently working on remaking flappy-bird without looking at tutorials and using my own research to do the code to help me get better at coding. I have one last bug to fix and that is when I click the restart button in the game over scene.
The score text ui overlaps its self with the previous score and sometimes incremates the score by 2 or 5, and I cant find a way to reset the score back to 0 once restart is clicked. I am using DontDestroy on the canvas so the score transfers over to the game over scene. Any help would be great.
THANKS!!!
Answer by unity_ka6jgzfPPmtNCw · Nov 14, 2021 at 02:15 PM
Do something like:
class SingletonClass: monobehaviour
{
public SingletonClass singletonClass;
void OnEnable
{
singletonClass = FindObjectOfType<SingletonClass>();
if (singletonClass != this)
Destroy(this.gameObject);
}
}
That way, if the class already exists when the new scene loads, it lets the old one stay and destroys the new one.
For the restart, add a script to your UI element, link the button to code like:
FindObjectOfType<SingletonClass>().ResetScore();
and make sure you have the method, ResetScore() in that SingletonClass.
Is SingletonClass class, a script your using as an example or a scrip I should make and attach?
It's just an example. A Singleton is something that you know there should only ever be one of in the scene, like the player or your Score Card, and above is just a way to implement and enforce it easilly
So I basically reference my score method then, correct?