Adding interactive content

How to add:

In game slideshows / text.

Other interactive things.

Displaying text when you are close to an object

Hint

If you just want to trigger text when you are near to a location then you should just add an empty game object to ┬áthe game ( Game Object > Create Empty), add a Sphere Collider ( Add Component > Physics > Sphere Collider) ┬áthen add the script to the empty object. Don’t forget to make the sphere collider a trigger!!!

Code
var sound : AudioClip; //This gives us the option to select an mp3 file in the properties pane var triggered: boolean; var style : GUIStyle; var textToDisplay: String; function OnTriggerEnter () { //This is the function that is fired when another object collides with this one. GetComponent.<AudioSource>().PlayOneShot(sound); // This is how we play the sound. We could do other stuff here instead. triggered = true; } function OnTriggerExit () { //This is the function that is fired when another object collides with this one. triggered = false; } function OnGUI() { if (triggered) { GUI.Label (Rect (0,0,Screen.width,Screen.height), textToDisplay, style); } }
Advanced code: Text slideshow
var sound : AudioClip; //This gives us the option to select an mp3 file in the properties pane var triggered: boolean; var looping = true; var style : GUIStyle; var text1 : String; var text2: String; var text3: String; var text4: String; var delay = 2.0; private var slide = 1; private var rotating = false; function OnTriggerEnter () { //This is the function that is fired when another object collides with this one. GetComponent.<AudioSource>().PlayOneShot(sound); // This is how we play the sound. We could do other stuff here instead. if (!triggered){ slide = 1; rotateText(); } triggered = true; } function OnTriggerExit () { //This is the function that is fired when another object collides with this one. triggered = false; } function OnGUI() { // This displays the requested text. Very inefficient - should be able to use a list/array. if (triggered) { if (slide == 1) { GUI.Label (Rect (0,0,Screen.width,Screen.height), text1 , style);rotateText(); } else if (slide ==2) { GUI.Label (Rect (0,0,Screen.width,Screen.height), text2 , style);rotateText(); } else if (slide ==3) { GUI.Label (Rect (0,0,Screen.width,Screen.height), text3 , style);rotateText(); } else if (slide ==4) { GUI.Label (Rect (0,0,Screen.width,Screen.height), text4 , style);rotateText(); } else if (slide ==5) { GUI.Label (Rect (0,0,Screen.width,Screen.height), "" , style);rotateText(); //improve this to hide the label } } } function rotateText(){ //This part controls what slide we are on and whether to loop the text. if (!rotating){ while (triggered){ rotating = true; if(slide < 4 ){ yield WaitForSeconds (delay); slide = slide + 1; } else{ if (looping){ yield WaitForSeconds (delay); slide = 1; } else{ slide = 5; yield WaitForSeconds (delay); } } } rotating = false; } }