Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: MedalOfMode on August 23, 2013, 05:14:54 AM

Title: Script Question
Post by: MedalOfMode on August 23, 2013, 05:14:54 AM
Why this script isn't working? I'm trying to show score.
  1. public int score = 0;
  2. public GameObject scoreLabel;
  3.  
  4.         void ScoreTextShow () {
  5.                 scoreLabel.GetComponent(UILabel).text(score.ToString());
  6.         }
Title: Re: Script Question
Post by: rain on August 23, 2013, 08:57:12 AM
Instead of storing a GameObject, you can create a UILabel field so you don't even need to GetComponent the UILable component.
  1. public int score = 0;
  2. public UILabel Label;
  3.  
  4. private void ScoreTextShow()
  5. {
  6.      Label.text = score.ToString();
  7. }
  8.  
Title: Re: Script Question
Post by: sabba2u on August 23, 2013, 09:29:47 AM
Try...


scoreLabel.GetComponent<UILabel>().text(score.ToString());
Title: Re: Script Question
Post by: OnlineCop on August 23, 2013, 12:27:26 PM
  1. public UILabel label;
  2.  
  3. private int mScore = 0;
  4. public int score {
  5.    get {
  6.       return mScore;
  7.    }
  8.    set {
  9.       if (value != mScore) {
  10.          mScore = value;
  11.          label.text = mScore.ToString(); // Automatically updates the label any time the score gets updated :-)
  12.       }
  13.    }
  14. };
  15.  

  ;)
Title: Re: Script Question
Post by: MedalOfMode on August 23, 2013, 03:31:02 PM
There is no text in screen? Can't we show text using script  :o Really, i tried a string too but really there is no text on screen.