Code for Text on Level Loading

This is the script to show text at the beginning of your level. This needs to be linked to a GUIText object. Adjust the time to suit. The text should be something simple like following with your technology and name inserted:

ISLAND OF THE COMPUTER by Andy Cox

Find the technology….
Press the Esc key for menu

For line breaks insert \n into your text.

private var StartTime : float;

/*OnLevelWasLoaded () runs once*/
function OnLevelWasLoaded () {

	/*set the start time to the start of the game*/
	StartTime = Time.time;

}

function Update () {

	/*if less than 5 seconds since start of game display the text*/
	if(Time.time - StartTime <= 5){
		guiText.enabled = true;
		guiText.text = "ISLAND OF THE COMPUTER by Andy Cox
               \n Find the technology....
                \nPress the Esc key for menu ";

	}
	/*otherwise destroy the game object to which the script is attached*/
	else {
		Destroy (gameObject);
	}

}

Leave a Reply