- Home /
 
Triggered on screen hint message.
Hey!
Is there a way in java to display certain text messages on screen for a short time, whenever the character hits a certain trigger?
I'm doing a demo and I wanted to include little hints on how to solve the coming puzzles.
Thank you!
Answer by thellama · Jul 30, 2012 at 03:55 PM
You should look into: http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html which will guide you through the basics of scripting your own windows for display using onGui whenever you need them!
 #pragma strict
 
 var message : String = "Change Me";
 var displayMessage : boolean  = false;
 var displayTime : float = 3.0;
 
 function OnTriggerEnter ()
 {
     displayMessage = true;
  yield WaitForSeconds (displayTime );
  displayMessage = false;
 }
 
 function OnGUI ( )
 {
     if ( displayMessage )
     {
         GUI.Label(new Rect(Screen.width * 0.5f - 50f, Screen.height * 0.5f - 10f, 100f, 20f), message);
     }
 }
 
               Here is a quick script you can place on the trigger to display the message.
Is the method for WaitForSeconds(float) the same for C#?
In C# the method must be ienumerator
Example:
public IEnumerator Wait$$anonymous$$ethod(){
yield return new WaitForSeconds(float);
}
Your answer