- Home /
Death collider
When this spheare hits me in the game i need it to kill me on inpact what would I type?
Answer by Tomer-Barkan · Jun 02, 2013 at 06:13 AM
Listen to this tutorial to learn how to handle collisions, you will need it: http://www.unity3dstudent.com/2010/07/beginner-b01-basic-collision-detection/
Now, when you're handling a collision, in OnTriggerEnter()
or OnCollisionEnter()
of the script attached to the object you want to destroy, simply use:
Destroy(this.gameObject);
to destroy the object
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html
http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html
function OnCollisionEnter(collision : Collision) {
// Debug-draw all contact points and normals
for (var contact : ContactPoint in collision.contacts) {
Debug.DrawRay(contact.point, contact.normal, Color.white);
}
// Play a sound if the coliding objects had a big impact.
if (collision.relativeVelocity.magnitude > 2)
audio.Play();
}
// $$anonymous$$ills the game object
Destroy (gameObject);
// Removes this script instance from the game object
Destroy (player);
// Removes the rigidbody from the game object
Destroy (rigidbody);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613103350im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Player "bumpes" when trying destroy onCollision 2 Answers
Mecanim Capsule Collider Issue 0 Answers
Boxcollider 2D Destroyed 2 Answers
Internal collisions 1 Answer
Physics2D.OverlapCircleAll returning colliders outside of the area 1 Answer