x


How Do I Make My Score Add Numbers Instead Of Strings?

I am trying to make a basic scoring system and it is adding strings not numbers. here are my script:

var score = 1; var GUIScore : GUIText;

function OnTriggerEnter( other : Collider ) { if (other.tag == "Coin") { GUIScore.text += score; Destroy(other.gameObject); } }

How do I make it add numbers instead of strings (It starts off at 0 and when I pick a coin up it displays 01 and then 011, etc.)

more ▼

asked Aug 19 '10 at 03:00 PM

MonkeyAssassin8 gravatar image

MonkeyAssassin8
271 35 38 43

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Try this:

function OnTriggerEnter( other : Collider ) 
{ 
if (other.tag == "Coin") 
{
score++; 
GUIScore.text = score.ToString();
Destroy(other.gameObject); 
} 
}

I hope it helps.

more ▼

answered Aug 19 '10 at 03:28 PM

diabloroxx gravatar image

diabloroxx
689 5 7 12

Yay it works. thanks heaps!

Aug 19 '10 at 03:37 PM MonkeyAssassin8
(comments are locked)
10|3000 characters needed characters left

when you gain score increase a numerical variable score and set it to be the newly displayed text - GUIScore.text = score; // not +=

more ▼

answered Aug 19 '10 at 03:21 PM

matyicsapo gravatar image

matyicsapo
659 12 15 27

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x271
x20
x19
x7

asked: Aug 19 '10 at 03:00 PM

Seen: 1377 times

Last Updated: Aug 19 '10 at 03:00 PM