Author Topic: Script Question  (Read 2385 times)

MedalOfMode

  • Guest
Script Question
« 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.         }

rain

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 4
  • Posts: 79
    • View Profile
Re: Script Question
« Reply #1 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.  

sabba2u

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Script Question
« Reply #2 on: August 23, 2013, 09:29:47 AM »
Try...


scoreLabel.GetComponent<UILabel>().text(score.ToString());

OnlineCop

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: Script Question
« Reply #3 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.  

  ;)

MedalOfMode

  • Guest
Re: Script Question
« Reply #4 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.