Author Topic: Label Error  (Read 3818 times)

southpaw

  • Guest
Label Error
« 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:



It also appears that the hover over highlight of the buttons stays visible after the mouse moves away. Any insight would help a ton!

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Label Error
« Reply #1 on: January 15, 2013, 01:08:25 PM »
Can you post the code you are using on button press that sets the label text?

southpaw

  • Guest
Re: Label Error
« Reply #2 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".

EToreo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 88
    • View Profile
Re: Label Error
« Reply #3 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.
« Last Edit: January 15, 2013, 03:41:38 PM by EToreo »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Label Error
« Reply #4 on: January 15, 2013, 11:16:55 PM »
Select the UI camera and set clear flags to be "color", not just "depth".

southpaw

  • Guest
Re: Label Error
« Reply #5 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.