I have a situation where I have levels in my game and a start screen. For the levels, there is a persistent empty GameObject. My code for setting the game over and level complete canvases active (Also button initializations eg. restart, quit, next level...)is attached to that empty game object. Further, the canvases mentioned are attached to the persistent object.
Would converting my persistence script into a singleton script be the best way to manage the behavior so that the canvases don't land up on the start screen (and unnecessarily slow the game) when I quit a level? I am planning on putting the persistent object in every level to test each level specifically.
As of right now this is what I'm planning on doing unless there are better patterns or suggestions. Any help would be appreciated!
if (instance == null || (SceneManager.GetActiveScene().name != "StartScreen"))
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}