How To Destroy An Item When It Touches Something?

I Need It So That When Spear Touches Man, Man Is Destroyed.

  • Attach a collision object to spear ( perhaps a box collider? )
  • Attach another to the Man.
  • check the (is trigger) box on both collision objects
  • Attach a rigid body to spear
  • probably wanna uncheck gravity on rigid body (I assuming you don’t want the object you’ve given a rigid body too become effected by gravity, you can also check the box “is kinematic” as well.
  • give the spear object a tag (“spear”)

Attach this code to the man;

 function OnTriggerEnter ( other : Collider )
     if ( other.collider.tag == "spear" )      
         Destroy ( gameObject );

Sorry I gave you the Javascript answer, I’m sure the C# version isn’t far off.

edit: my bad I forgot the brackets on gameObject!

C# version, in case you use C#:

void OnTriggerEnter (Collider collider) { if (collider.gameObject.CompareTag ("TAG")) { Destroy (gameObject); } }

Place this on your “man” or player. Replace “TAG” with the tag of the item you are running into.