- Home /
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.)
Answer by diabloroxx · Aug 19, 2010 at 03:28 PM
Try this:
function OnTriggerEnter( other : Collider )
{
if (other.tag == "Coin")
{
score++;
GUIScore.text = score.ToString();
Destroy(other.gameObject);
}
}
I hope it helps.
Answer by matyicsapo · Aug 19, 2010 at 03:21 PM
when you gain score increase a numerical variable score and set it to be the newly displayed text - GUIScore.text = score; // not +=
Your answer
Follow this Question
Related Questions
Using Buttons to write numbers 3 Answers
Displaying score with zeros in front of var (i.e. 0025 instead of 25) 4 Answers
Dividing On strings CS0019 1 Answer
Score going up every second 1 Answer
distance based score system 3 Answers