- Home /
Collect some coins for Points
Hi... I have a terain and the 3rd Person Controller in my scene. There is no problem on them i can press play and walk,run and jumb on my terain.
I want to make a Coin system so when my player collect some coins(every coin is 5 points) to be able to show on the top right of my screen "Score:points here".
So far i have a Sphere as Coin with the Sphere Collider and the collider is set to Trigger. The name of my Sphere in Hierarchy is Coin. I have this script
var score = 0;
function OnTriggerEnter( other : Collider ) { if (other.tag == "Coin") { score += 5; Destroy(other.gameObject); } }
Finally i have this script attached on my 3rd Person Controller. When i press play and go to my coin to catch it and then destroy it none of this things is happening. Also i don't know if i caught the Coin because I have no Script to show me how many points i have. Please a little help here. I thing its easy to fix this. Thank you.
Answer by Jesse Anders · Nov 22, 2010 at 04:01 PM
You said the name of the 'coin' object is 'Coin'. Is it also tagged as 'Coin'? (Because you're checking the tag, not the name.)
If that's not the problem, try using the debugger (if you're using Unity 3), or add some debug output to help determine what's actually going on. Specifically, I would add some calls to Debug.Log() to your OnTriggerEnter() function, e.g.:
function OnTriggerEnter( other : Collider ) {
Debug.Log("OnTriggerEnter() was called");
if (other.tag == "Coin") {
Debug.Log("Other object is a coin");
score += 5;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
}
well i got only the "OnTriggerEnter() was called" so its not tagged. Can you explain me how to tag it as Coin? Please?
ok thank you i tagged it and now the gameobject is destoyed when i touch it and i get "Score is now 5"
thank you very match.
Your answer
Follow this Question
Related Questions
Creating a SIMPLE car. 1 Answer
Manual collision check 2 Answers
Same reaction with different number of objects colliding 2 Answers