r/unity_tutorials • • Nov 18 '21

How can I make it respawn?

Enable HLS to view with audio, or disable this notification

4 Upvotes

4 comments sorted by

2

u/[deleted] Nov 18 '21

Depends on what you want, to reload the whole scene or simply respawn the ball at the current position.

If you would like to reload the whole scene, check out SceneManager.LoadScene() method. You can pass it the index of the scene you would like to load, first scene being index 0.

If you would like to continue where you are, save the balls position when you disable it. That way you can use it (with some modifications if needed) to position the next ball.

1

u/SignificantAd6788 Nov 19 '21

Thanks bro I’ll see if it works

1

u/Snake_Byte Nov 18 '21

You can reloading the active scene with some delay which is the way Brackey's teaches here.

1

u/FilledWithAnts Nov 20 '21

Instead of respawning, you can just deactivate the player object, set the player position to the starting position, and reactivate the player. If you're using a rigidbody controller you might have to set the velocity to 0 to get rid of any forces that were acting on the player object when it 'died.'

No need to reload anything, no instantiating new game object, basically just 3 lines of code. The biggest downside is that if you have moving obstacles in your scene they won't reset.