- Home /
Collision detection on cube with third person camera
What I want is to be able to destroy the cube when the third person character hits the cube...I have this code so far:
#pragma strict
var other : GameObject;
function Start () {
}
function Update () {
}
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name=="Character") {
Destroy(gameObject);
}
}
But it is not working, the third person camera is called 'Character', and the cube is called 'Cube1'.
Any suggestions will be appreciated!
Add a Debug line to make sure that you are actually hitting "OnCollisionEnter". From there, you can debug what the name of the collision gameObject is, and potentially get more information about your issue. (i.e. are you missing colliders, rigidbodies, etc.)
Answer by Oribow · Jul 02, 2013 at 10:00 PM
Check your Collision with Tags.
Make your own Tag example "Person"
Add the Tag to all GameObjects from your Charactercontroller
Write in the Script gameobject.tag == "Person"
Then may it works.
Your answer
Follow this Question
Related Questions
Adding sound javascript in unity2d 1 Answer
Cloud recognition in Vuforia 0 Answers
Creating and removing HUDs on Collision 1 Answer
JavaScript - Reset Characters Position 2 Answers
Strange problem with OnTrigger 0 Answers