Hello, I’m making a 2D platformer game and I’m using DontDestroyOnLoad for the player game object so it can persist through scenes. However, there are some scenes I don’t want the player to be in, like the leaderboard scene or the game over scene. I’m still relatively new to game development and am wondering if there’s a way to prevent the player from being in certain scenes even though it’s in DontDestroyOnLoad? Thanks in advance and I appreciate any help.
It really depends on the structure of your game. There are multiple ways of doing this, one way is to have some sort of gameManager in DontDestroyOnLoad and storing a reference to the player in it. This makes it so that you can then enable/disable the player whenever you want. The gameManager could be responsible for the scene switching and in the function that loads a different scene, simply have some sort of check wether or not to load the player.