Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You are missusing the singleton pattern.
- The correct use would be this:
- In `ScoreKeeper`
- ```lang-cs
- public class ScoreKeeper : MonoBehaviour
- {
- public static ScoreKeeper Instance { get; private set; }
- private void Awake()
- {
- if (Instance != null && Instance != this) // if we are the instance this is fine
- {
- Destroy(this);
- return;
- }
- Instance = this;
- DontDestroyOnLoad(this);
- }
- }
- ```
- Then when accessing it, don't hold on to a reference, just do this each time.
- ```lang-cs
- ScoreKeeper.Instance.ResetScore();
- ```
- Your error was occuring becuase `LevelManager`'s reference was somehow becoming null, likley because loading into the game made the original `ScoreKeeper` delete itself due to the error in it's awake logic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement