- Home /
OnCollisionEnter Collision not detected?
I can't figure out what I am doing wrong. I have a sphere acting as the player and a cube with the MoneyCollect tag. What is supposed to happen is the sphere collides with the cube, 100 dollars is added to the player and the cube is destroyed. For some reason, the collision of the objects is not detected, I am able to go right through the cube without triggering the collision. Here's my code:
function OnCollisionEnter(hit : Collision){
if(hit.collider.tag == "MoneyCollect"){
money += 100;
Destroy(hit.gameObject);
}
}
Answer by fendorio · Apr 16, 2014 at 11:44 PM
Change
if(hit.collider.tag == "MoneyCollect")
To
if(hit.gameObject.tag == "MoneyCollect")
Maybe :P
Other than that check the standard things. Is the tag actually assigned? Be surprised how many times people slip on on that haha xD I.e. me... all the time lol
Tried that, still doesn't work. The tag is definitely assigned.
Your answer
Follow this Question
Related Questions
Unity 2D Colliders not Colliding 2 Answers
Check if collider is colliding with anything non specific? 1 Answer
Make isKinematic false when touching a Collider? 1 Answer
How would I be able to subtract from a variable when it hits something? (OnCollisionEnter) 1 Answer
How do I pass through certain colliders but detect all collisions? 1 Answer