- Home /
collison scoring
i made a script that would increase the coin counter by 1 everytime it collides with a coin but my script either adds 2 or doesnt do anything. Anyone know how to fix this script?Thanks
public int coin = 0;
public GUISkin myskin;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "coin") {
coin += 1;
}
}
void OnGUI()
{
GUI.skin = myskin;
GUI.Label(new Rect(200,10,200,100), "Coins:" + coin);
}
No that doesnt work. i also cant make it into a 2D collider because the coin has rigidbody
Yeah the 2D is because I was using 2D but I think you want 3D therefore just add a $$anonymous$$esh Collider or whichever collider you want and make it trigger and call the OnTriggerEnter function
i just added in a bool and an update and fixed it myself somehow :)But Thanks anyway
Answer by tebandesade · Mar 18, 2015 at 08:51 PM
Hi! I just did something like this and works fine
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "coin")
{
coin ++;
}
}
instead of making it +=1 just make it ++ . Also make your the coin is a trigger collider then . I also did it with 2D so please bare in mind also.
Your answer
Follow this Question
Related Questions
Can't click gameobject when over another trigger? 1 Answer
How to add score with no trigger 0 Answers
Can it be detect several colliders in the same gameObject? 0 Answers
Character's trigger collides with itself 2 Answers
How do you detect which collider is triggered when you have multiple? 2 Answers