Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Colin Allen · May 07, 2010 at 05:49 PM · gameobjectdestroyenemycollideon

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tetrad · May 07, 2010 at 10:18 PM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
5

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 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

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)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image oinkoinkflapflap · Nov 27, 2010 at 10:38 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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

Collecting items when you destroy something? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges