• 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
Question by userpay · Oct 31, 2010 at 03:58 PM · destroyexplosionmissile

Missile Collision and Explosions

Okay so I want to make it so that when my missiles collide with somet$$anonymous$$ng they explode(terrain, object, ect), how would I set t$$anonymous$$s up? Note I have downloaded the Detonator extension.

Currently I've got targets that go down just from getting $$anonymous$$t, how would I arrage for the explosion made (most likely would use either the simple or tiny explosion if I use a premade one) to be what knocks the targets down?

And if you would so kindly provide some example code for the above questions? I'm just barely starting out using Unity so if you just tell me where to put it I might not quite get it. Thank you ahead of time.

Comment

People who like this

0 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 KrisCadle · Jul 26, 2011 at 10:30 PM 0
Share

Here's something i copied from a longer script i wrote for a game. Basically the idea is you put this on your missile prefab and then when you instantiate it from a button or whatever it will fly forward on its Z axis and at whatever speed you put in the code (right now it's set to 100) Then when it hits something it will explode and destroy itself. It can also do something depending on what the Tag is of the object it hit (like add different scores for different objects)... I have not tested this exact script but it will point you in the right direction ;)

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by KrisCadle · Jul 26, 2011 at 10:25 PM

     //attach your explosion prefab in the editor 
     
     var explosion : GameObject;
     
     static var score : float;   
         
         
     //gives the missile its speed
 
 function FixedUpdate () {
     
            rigidbody.AddForce (transform.TransformDirection (Vector3.forward) * 100.0);
     
         }
         
         
     function OnCollisionEnter(collision : Collision) {
         
             var contact : ContactPoint = collision.contacts[0];
             var t$$anonymous$$sExplosion : GameObject = Instantiate (explosion, contact.point + (contact.normal * 5.0) , Quaternion.identity);
         
 //here you can set a tag so when your missile $$anonymous$$ts different stuff it can add different scores or have different explosions
         
             if (collision.gameObject.tag == "enemy")
             {
             score = score + 100;
             Destroy (collision.gameObject);
             
             Instantiate (explosion, contact.point + (contact.normal * 5.0) , Quaternion.identity);
             
             }
         
         }
         
         Destroy (t$$anonymous$$sExplosion, 2.0);
         Destroy (gameObject);
             
             
         }
Comment
Myles Jones

People who like this

1 Show 0 · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Destroy Object when scene loads 1 Answer

Help with destroying within a certain zone... 1 Answer

Enemy's wont die if spawned 1 Answer

Streaming Game Content 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