This does remove the player, but it removes both players, the original and the duplicate. If anyone knows why this happens and how I can fix my problem, I would really appreciate it.
If both your scenes contain a player, why are you setting it to no be destroyed when you transition scenes (DontDestroyOnLoad)? Seems like the easiest way to fix this is to just allow the player to be destroyed with the scene.
Why do you feel you need it. If it is to have your data carry over from scene to scene then you should consider using PlayerPrefs (or a similar alternative) to save and restore the data.
Posted this as answer but apparently it’s waiting for a moderator to approve it…
When changing scenes in Unity the default behaviour is for all objects in the current scene to be destroyed before the next scene is created. By calling DontDestroyOnLoad(transform.gameObject); you are telling unity not to destroy the player when changing scenes. If your second scene also has a player object in it then you will now have two players, one from the first scene that never got destroyed and the one that’s in the second scene.
I would try removing that call and letting the player be destroyed when you change scenes unless there’s a particular reason you need that player to persist across scenes. Essentially I’d remove this whole block.
If both your scenes contain a player, why are you setting it to no be destroyed when you transition scenes (DontDestroyOnLoad)? Seems like the easiest way to fix this is to just allow the player to be destroyed with the scene.
– cdnDaveA vector represents a direction
– CaioRosisca