- Home /
Label not updating when text changed through javascript send message.
I'm basically trying to toggle the value of a label using a button in my web page and a button in the player. If I click my test2 button the string updates and the label changes, no problem. When I call the SetLabel method from my javascript using send message the labeltext doesn't seem to be updating. I know SetLabel is being called because my testmessage2 javascript function shows an alert. Is there something about calling functions from a web page that makes them act differently?
public void SetLabel(string labeltext)
{
labeltext = "javascript called";
Application.ExternalCall("testmessage2");
}
void OnGUI()
{
if (GUI.Button(new Rect(0, 0, 100, 100), "test"))
{
labelvisible = true;
}
if (labelvisible)
GUI.Label(new Rect(0, 200, 100, 300), labeltext);
if (GUI.Button(new Rect(100, 0, 150, 50), "test2"))
{
labeltext="button pressed";
}
}
Answer by thornekey · Mar 07, 2014 at 12:48 AM
if (labelvisible) {
labeltext = GUI.Label(new Rect(0, 200, 100, 300), labeltext);
if ((GUI.Button(new Rect(100, 0, 150, 50), "test2")) {
labeltext = "buttonpressed"
}
}
sorry bout the formatting, on phone - havent tested code
Label method returns void, that won't work. Not sure what you're attempting there.
Your answer
Follow this Question
Related Questions
How much data can I send from the browser through unityObject.SendMessage()? 1 Answer
Web Player SendMessage Array Parameters 1 Answer
Problem with UnityObject2.SendMessage | communicating with the web player 0 Answers
Send a message to multiple scripts within an Array - Javascript 1 Answer
SendMessage Not Working: JavaScript 1 Answer