Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Davud · Nov 25, 2013 at 10:15 PM · gameobjectinstantiatedestroyoncollisionenter

Guided Missiles help?

How to destroy a missile after it explodes?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by N1warhead · Oct 03, 2014 at 09:32 PM

This is how you making a Missle Instantiate and find an object(s) with a certain tag! It is in C#. You may have to change it to suit your needs better, but it does work! Attach this script TO YOUR PREFAB THAT GETS INSTANTIATED!

 Transform Target;
     float Speed = 20f;
     float MaxDistance = 50f;
     float DieTime = 1.5f; // Destroyed in 1.5 seconds (Change to                                 
                            // Change to your needs!)
 
     void Start(){
 
         DieTime = Time.time;
         Target = GameObject.FindGameObjectWithTag ("Player").transform;
 
 
         }
     
 
     // Update is called once per frame
     void Update () 
     {
                 transform.LookAt (Target);
                 AI ();    
                 if (Time.time - DieTime > 1.5f) {
                         Destroy (this.gameObject);
                         Debug.Log ("DESTROYED BY TIME");
                         Destroy (this.gameObject);
                 }
         if(Target == null){
             Target = GameObject.Find ("Player").transform;
         }
     }
         
         void AI()
     {
         if (Vector3.Distance (transform.position, Target.position) <= MaxDistance) {
                         transform.position += transform.forward * Speed * Time.deltaTime;
                 }
         }
 
 
         
         void OnDestroy(){
         if (Target) {
             Destroy (gameObject);
                         Debug.Log ("Missile Destroyed");
                 }
         }
     }
 


As said, you may have to change things up for your needs, but this DOES WORK! in C#.

Hope this answered your question properly! If so please mark as answered.

Comment
Add comment · Show 2 · 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 Davud · Oct 03, 2014 at 09:56 PM 0
Share

N1warhead thx. I have updated my question because i had changed it before. Jamster is right about his comment. Newbie mistake

avatar image N1warhead · Oct 03, 2014 at 10:18 PM 0
Share

You're very welcome buddy.

Don't feel bad, yesterday I sat around trying to figure something out and I made the most rookie mistake ever...

We all go through it, just takes patience and dedication. Some stuff is easy some stuff is hard, but if you really think about it, most stuff you do for just an ordinary game is all explanatory with the basics we just skip past the basics because we think it's not basic, when in reality it is, but it isn't if you don't know how to get an out of the box view of the problems we face.

I'm glad I was able to help you. If you ever have any questions, feel free to message me if you'd like. I don't know everything, but more pairs of eyes is better than one pair.

avatar image
0

Answer by Jamster · Nov 25, 2013 at 10:37 PM

Destroy(gameObject) will destroy the game object the script is attached to, if you're using OnCollisionEnter() on the missile try this instead:

 function OnCollisionEnter(col : Collision){
 
     Destroy(col.gameObject);
 
 }

That will destroy the object it hits instead. If you wanted an explosion etc to appear first it must be called before the Destroy otherwise it wount be read!

Comment
Add comment · Show 2 · 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 Jamster · Nov 26, 2013 at 05:48 PM 0
Share

O$$anonymous$$, you've changed your question so (aside from my answer not making sense now) you seem to be asking some thing different. How do you mean "add force to a missile before it explodes"? Do you mean the missile or do you mean the thing it hits? Have you tried using rigidbody.AddForce or just using Transfor.Translate?

avatar image Davud · Oct 03, 2014 at 08:22 PM 0
Share

After more than a year, i see my old questions "i say wow it was a big struggle to learn program$$anonymous$$g and other necassary 3d work.". Even after a year, there is still so much things to learn.

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Trash Collection For Instantiated Game Object 1 Answer

How to instantiate a prefab after its been destroyed 1 Answer

Instantiating prefabs: "The object of type GameObject has been destroyed". 1 Answer

Instantiate problem 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