- Home /
Score Counter
I have my script and it will create a counter for me. My counter will not count the points. Is there any way i can fix this?
The script is in java Script: var score = 0; var scoreText = "Score: 0"; var mySkin : GUISkin;
function OnTriggerEnter( other : Collider ) { Debug.Log("OnTriggerEnter() was called"); if (other.tag == "point") { Debug.Log("Other object is a point"); score += 1; scoreText = "Score: " + score; Debug.Log("Score is now " + score); Destroy(other.gameObject); } }
function OnGUI () { GUI.skin = mySkin; GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString()); }
Answer by fafase · Mar 30, 2012 at 06:38 AM
I think the answer has been removed since I don't see it anymore...(well done)
You error is in if (other.tag == "point") it should be if(other.gameObject.tag == "point")
Notice the small g and the O.
oh, I didn't write this and I'm really bad at javascript, Thanks
Get back to your original post and update the code as you are susing it now. Also when you are done writing, select the whole code section and click the 101010 button in the tool bar. That will make your code look like code and thus easier to help you. Detail a little more what you mean by fail and lag, what is happening what error do you get, is the score increasing on your console?
Answer by garner · Mar 31, 2012 at 10:48 AM
it seems like scoreText = "Score: " + score;
could be scoreText = "Score: " + score.ToString();
but I haven't checked it sorry.
you don't need .ToString() + is already doing it. I guess the operator is overloaded.
Your answer
Follow this Question
Related Questions
How to give a bonus every 1000 points? 2 Answers
Scoring (i'm stuck) 3 Answers
Make a custom score counter in unity with c# 1 Answer
Trying to get score counter... 2 Answers
how to keep track of bricks broken 1 Answer