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. :)
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
}
`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.