Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: faceOFF on July 10, 2012, 01:57:08 AM

Title: Score to string in NGUI.
Post by: faceOFF on July 10, 2012, 01:57:08 AM
Greetings to all!

I use JS:
  1. function Update()
  2. {
  3.         //draw the score in NGUI
  4.         GameObject.Find("LabelScore").GetComponent(UILabel).text += scorePoints;
  5. }
  6.  

Thus UILabel out display not the Score but infinite line of figures.
Example, if the Score is equal to zero, it deduces:
000000000000000000000000000000000000000000000000000 (infinitely).
How to solve? There is a something like .ToString () for (UILabel).text?

Excuse for my english ;)
Title: Re: Score to string in NGUI.
Post by: dlewis on July 10, 2012, 02:03:32 AM
You should be keeping a local variable of the score and every time that is updated then update the label, don't use the use the label as data storage.

  1. int score = 0;
  2. score += scorePoints;
  3. label.text = score.ToString();

I use C# so I don't know if javascript has ToString so you could use...whatever the javascript equivalent is for printing a value to string and then assigning it.
Title: Re: Score to string in NGUI.
Post by: ArenMook on July 10, 2012, 02:04:43 AM
GameObject.Find in Update is a VERY slow operation.

Change it to a public reference instead:
  1. public UILabel scoreLabel;
...then set it in inspector via drag & drop.

P.S. This is C# code. I don't use javascript, so I can't support it.
Title: Re: Score to string in NGUI.
Post by: faceOFF on July 10, 2012, 02:19:35 AM
You should be keeping a local variable of the score and every time that is updated then update the label, don't use the use the label as data storage.

Wow! Great!!! Thanks a lot!
It's work in JS:
  1. function Update()
  2. {
  3.         //draw the score in NGUI
  4.         var score = scorePoints;
  5.         GameObject.Find("LabelScore").GetComponent(UILabel).text = score.ToString();
  6. }

GameObject.Find in Update is a VERY slow operation.

Ok, I will try, and to you thanks for council!