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!!!

1 Answer

1

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?