Quantcast
Channel: Answers for "Displaying Text On touch"
Viewing all articles
Browse latest Browse all 4

Answer by lhk

$
0
0

I'm not using Javascript but I've done something similar in c#. Create a GameObject and add a GUIText to it. Then write a script like this. Note that the c# code is just a "short version"

public static bool on; // switch the messages on and off
public static string text;  //text to be displayed
GUIText messages // this will hold the GUIText component, to access its text

void Start()
{
    messages=(GUIText)GetComponent("GUIText");
}
void Update()
{
    if(on)
    {
        messages.enabled=true;
        messages.text=text;
    }
    else
    {
        messages.enabled=false;
    }
}

Now you can access the GUI messages by adjusting the static variables of your script. Let's assume you named your script "texthints". Then the following should work:

void OnCollisionEnter (Collision col) 
{
    texthints.text = "On No... You Died, Try Again";
    texthints.on=true
    Application.LoadLevel(1);
}

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images