I'm trying to restart my game when the player loses, I play a coroutine which makes the player ignore collisions and falling off the platforms. Then when the player click a button, the same scene is reloaded.
SceneManager.LoadScene("GameScene")
But when the scene loads again, the player is still ignoring collisions and falls, it's like the scene is loaded but not the same way when the game is played for the first time.
¿How can I reload the scene properly without closing the aplication and opening it again?
Thank you.
CodePudding user response:
The problem is that you are using Physics2D.IgnoreLayerCollision
for this.
This property is global, it affect all scenes, and not related to the specific scene. What SceneManager.LoadScene
resets is only property related to the specific scene or the objects in the scene.
You have 2 options here:
Don't use
IgnoreLayerCollision
. An alternative may be, for example, to disable all colliders on the player. You can useGetComponentsInChildren
for example to find all the colliders.Reset
IgnoreLayerCollision
manually.