Singleton Patten score not resetting on loss

Hi All,

I didn’t see anything in the Q&A under this lecture or the following bug-fix one, so its possible this is an issue I caused myself!

The problem faced is that after the ball drops off the screen and triggers the LoseCollider.cs, the score persists on screen.
It remains on screen after the “Start Menu” scene is loaded and even when a new game is launched.

EDIT: I jumped to the forums prematurely! Seems this is covered in another lecture shortly after the aforementioned.
I have masked my solution in case those of you who stumble onto this want to take on the challenge yourselves.

I resolved this by adding a couple lines to the LoseCollider.cs to find the GameStatus object and destroy it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LoseCollider : MonoBehaviour
    // Config params
    GameObject gameStatus;
    private void OnTriggerEnter2D(Collider2D collision)
        gameStatus =  GameObject.Find("GameStatus"); 

    IEnumerator waiter()
        yield return new WaitForSeconds(1);
        SceneManager.LoadScene("Game Over");

Hopefully this is useful for anyone encountering the same.

1 Like

Awesome job for figuring it out here and putting the answer for us if we run into the same problem.

Privacy & Terms