- Home /
Question by
FLASHDENMARK · Dec 17, 2010 at 09:29 AM ·
destroyoncontrollercolliderhit
Destroy on impact dont work
Hello everyone
This seemed like a very easy job, and i have done this before, but now i cant make it work. I want to destroy a object when it collides/hit with a gameObject.
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "wall") // The object it hits IS tagged "wall"
{
Destroy(this); //Destroys the object the script is attached to.
} }
But Freaking hell i cant make this work now. Can you possible help me? Thanks in advance. :)
Comment
Best Answer
Answer by schwertfisch · Dec 17, 2010 at 09:55 AM
I am very new to Javascript but on similar occasions I use something like:
function OnTriggerEnter (col: Collider)
{
if (col.gameObject.tag == "wall"){
Instantiate(soundEffect, transform.position, transform.rotation); //this will make a sound effect on collision
Destroy(gameObject); //this will destroy the object the script is attached to
}
Best Answer
Answer by uhahaha · Dec 17, 2010 at 10:01 AM
function OnControllerColliderHit(hit : ControllerColliderHit) is to be used for a game object with the Character Controller component. Use OnCollisionEnter or OnTriggerEnter as the above answer says.
Your answer