- Home /
On Collide Destroy Game Object
Hi. this is a simple question. but id like a script that made it so when a collided with a certan game object it will delete it from the level.
Thanks!!! Post a script.
There are a lot of questions that answer this question. For example, from the search results just of what you put in the title: http://answers.unity3d.com/search?q=On+Collide+Destroy+Game+Object+, you get to this thread: http://answers.unity3d.com/questions/4145/how-to-make-objects-collide-and-something-happen which asks and has answered this exact question.
Answer by Mike 3 · May 07, 2010 at 06:04 PM
var certainGameObjectName : String = "Bob";
function OnCollisionStart(collision : Collision) { if (collision.gameObject.name == certainGameObjectName) { Destroy(collision.gameObject); // destroys the thing this script bumped into }
}
Answer by oinkoinkflapflap · Nov 27, 2010 at 10:36 PM
var explosionPrefab : Transform;
function OnCollisionEnter(collision : Collision) { // Rotate the object so that the y-axis faces along the normal of the surface var contact : ContactPoint = collision.contacts[0]; var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal); var pos : Vector3 = contact.point; Instantiate(explosionPrefab, pos, rot); // Destroy the projectile Destroy (gameObject); } function Update () { }
then put your explosion prefab in, (save the script then click and drag your explosion onto the empty slot) if you do not have an explosion prefab you can download 1 free of the unity website, link below :)
http://unity3d.com/support/resources/unity-extensions/explosion-framework
this is great, it gives you loads of explosion prefabs (if u want 2 publish i think they have copyright though, not sure look into it)
i dont know how 2 do the fancy script thing, you may have to rearange that on different lines and stuff, or not, im not sure, sorry :P
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
How to destroy GameObject's script(s)? 3 Answers
Destroy on collision 3 Answers
Why won't this object destroy? 2 Answers