Gamespace: Restarting Game

I have set the Gamespace to restart whenever a player falls off the edge of the world or the health bar points have decreased to zero due to the rain cloud enemies.

I found that if I put a cube underneath my landscape and the player collided with it (due to falling off) I could set the Gamespace to restart which means that the player does not need to manually restart the game by reloading the exe file.

I made this cube invisible by removing the mesh renderer component as the Gamespace would look unprofessional and messy if the cube could be seen. A tag named 'Respawn' is attached to the cube so that it can be identified in the script.



Restarting the Game by falling using collisions


This is the inspector for the restart cube, a box collider has been added to the object so that the script can detect when the player has fallen off of the landscape.


Restart Cube Inspector

The 'Respawn' script detects when a collision has occurred with the invisible box meaning that the player has fallen by using the gameObject tag 'Respawn'. The script simply states that if a collision has occurred with an object that has the tag 'Respawn' set to it, the scene named 'Gamespace' will reload.


Respawn Script


When restarting the scene after a fall or due to the player's health points decreasing to zero, the scene seems to always lose its material colours. This isn't a problem or mentioned as a significant error flagged up in the console. I attempted to fix this problem, however, I discovered that this problem only occurred during testing using the program. Once the Gamespace is exported ('build and run') this problem disappears and the game restarts exactly like it should.



Restarting the scene Game View

Comments

Popular posts from this blog

Unity Project 4: Ball platformer game

[Research] Traditional Poster Design (4CTA1214)