Before updating to Windows 10 you may need to return your Pro license. More information here

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.

more ▼

asked May 07, 2010 at 05:49 PM

avatar image

Colin Allen
136 15 16 18

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.

May 07, 2010 at 10:18 PM Tetrad
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

var certainGameObjectName : String = "Bob";

function OnCollisionStart(collision : Collision) { if (collision.gameObject.name == certainGameObjectName) { Destroy(collision.gameObject); // destroys the thing this script bumped into }


more ▼

answered May 07, 2010 at 06:04 PM

avatar image

Mike 3
34.6k 28 156 319

(comments are locked)
10|3000 characters needed characters left

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 :)


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)

more ▼

answered Nov 27, 2010 at 10:36 PM

avatar image

287 160 543 151

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

Nov 27, 2010 at 10:38 PM oinkoinkflapflap
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: May 07, 2010 at 05:49 PM

Seen: 36796 times

Last Updated: May 07, 2010 at 05:49 PM