Monday, 6 February 2012

Respawning Script for Unity

Matt Jonas wrote a Respawn script for the Unity engine so that if the player were ever to fall through the environment (unitentionally, of course), the player will instantly be respawned back at a specified origin point. This can be tailored in each scene so that the player is always returned to the correct location.

The code checks on every Update (which means every frame rendered) if the player has fallen twenty metres below origin. If they have, the game returns the player to a specified point (which can be changed in each scene). The script will also return the player's facing to the correct direction.

 

This was the first script written by Matt Jonas to familiarise himself with the Unity engine and to remind himself how to compose correct Javascript. 

Unity supports C#, Javascript and BooScript. In fact, a combination of any, so long as a file is composed in only one language. Multiple files (each composed in a single language) can be combined, even though those files may not all be written in the same language.

No comments:

Post a Comment