Framework 1: Respawning

Because I suck at playing this game, I need a respawn!

Simon Truong
3 min readJun 8, 2021

--

As I add more and more features, my game has become more complex with the difficulty of the game play sky rocketing. Due to my lack of talent to finish playing my game, and because I refuse to give myself 999 lives, I decided to create an respawn function that is called when the Game Over menu pops up. (trust me, I have seen this screen more than I should)

Disclaimer: So there are various methods in creating an respawn function and I strongly believe that the method I am going to be showing you is not the most optimized way. Hence this article is more of a self journal then any thing else.

Scripting

For this feature to function properly, we need to be addressing several components. The Player, the UI manager, the Spawn manger and the Game manager. Since each part is basically linked to each other, it is important not to forget any of these components.

The Player:

In the player script, we first need to create a handle for the player game object. Then in the Damage method we are going to do some small changes, instead of destroying the player when Lives = zero. We are simply going to disable the the player.

Next we are going to create a new public method called Player Respawn. In this method we are going to be giving the player full health, turning the player game object back on again, and updating the UI manager to show the 3 new lives and also triggering the spawn enemy coroutines from the Spawn Manager.

We will also be turning all damaged effects back to false.

The Spawn Manager:

In the spawn manager script we need to add another new public method with a Boolean to tell the stop spawning to be false. This is to counter the “On Player death” method which tells the spawn manager to stop spawning.

The Game Manger:

In the Game Manager, we again are going to create a new public method to counter the game over method.

The UI Manager:

Finally the UI manager, where everything comes together. In the previous article we have already mention that we have already created an public method called Game Over. Now its time to create another public method called Respawned.

In this new method, it is going to contain the newly created Player method “Player Respawn”, the Game Manager new public method “Respawned” and the Spawn Manager public method “Start Coroutine”. It will also disable the Game Over menu.

The Respawn Button:

Save everything, and back in the hierarchy select the respawn button on the Game over menu. In the “On Click” area, we are going to add a new function and drag the the Canvas component (since it has the UI Manager script) and select the public function “Respawned”.

The result “hopefully”… would have your player come back! Again this article is all but experimental as I, myself am still learning the codes.

--

--

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.