Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: southpaw on January 15, 2013, 12:58:27 PM

Title: Label Error
Post by: southpaw on January 15, 2013, 12:58:27 PM
I have two buttons (male/female). When the user picks a button, the text in a label is updated with the gender. This appears to work fine, but the old text is not being removed and the new text overlaps with it. It's a strange error, as it only appears when I build the scene (I've tried both Windows and web). The GUI works fine during Play mode in the Unity editor.

I put a screenshot on imgur:

(http://i.imgur.com/n74T4.png)

It also appears that the hover over highlight of the buttons stays visible after the mouse moves away. Any insight would help a ton!
Title: Re: Label Error
Post by: EToreo on January 15, 2013, 01:08:25 PM
Can you post the code you are using on button press that sets the label text?
Title: Re: Label Error
Post by: southpaw on January 15, 2013, 01:16:34 PM
void Update ()
{
PassStringToLabel("GenderLabel", info.gender[currentSelection]);
}

public void PassStringToLabel(string labelName, string info)
   {
      GameObject obj = GameObject.Find(labelName);
      UILabel lbl = obj.GetComponent<UILabel>();
      lbl.text = "";
      lbl.text = info;
   }


info.gender is a string list in another class. The name of the label I'm changing is "GenderLabel".
Title: Re: Label Error
Post by: EToreo on January 15, 2013, 02:28:34 PM
Try restructuring this so the value of the label is not dependent on the Update loop.  This could be causing the problem, it's also just a better structure for your code and eliminates quite a bit of computational overhead (setting a text mesh is an expensive operation and you are doing it "every frame").

NGUI offers some nice utilities to help you with this, UIButtonMessage being one of them.
Title: Re: Label Error
Post by: ArenMook on January 15, 2013, 11:16:55 PM
Select the UI camera and set clear flags to be "color", not just "depth".
Title: Re: Label Error
Post by: southpaw on January 16, 2013, 11:37:34 AM
Changing the clear flags fixed everything. Thank you! I realize that calling said function in Update() is not the optimal route, but it works and doesn't tax the program. UIButtonMessage will be helpful in the future though. Thanks for both of you, much appreciated.