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 Marcus · May 19, 2010 at 10:18 PM · destroytimeshootexplosion

Rocket to disappear after a few seconds?

HI!

I Have two problem that is driving me nuts.

  1. I need my rockets to disappear after a few seconds and starting an explosion animation, i have tried using the code destroy gameObject but then it destroys the whole ship i need a code that destroys my rockets (which are prefabs)

  2. I also need a delay from when i can fire again.

var prefabRocket:Transform;

var shootForce: float;

function Update () {

if(Input.GetButtonDown("Jump")) { var instanceRocket = Instantiate(prefabRocket, GameObject.Find("fighter/spawn1").transform.position, transform.rotation ); instanceRocket.rigidbody.AddForce(transform.forward * shootForce);

 }

}

Your help is much appreciated....

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
1
Best Answer

Answer by Mike 3 · May 19, 2010 at 11:01 PM

Easy way to destroy after a few seconds is to do this when you instantiate:

Destroy(instanceRocket, 3.0);

where 3.0 in my example is 3 seconds for it to live

on top of that, a simple way to start a particle explosion when it destroys is to just add a script with an OnDisable function, and instantiate a particle system in that

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 Marcus · May 20, 2010 at 02:10 AM 0
Share

I tried using Destroy(instanceRocket, 3.0); but i got this error cant remove transform because Rigidbody depends on it?

avatar image Mike 3 · May 20, 2010 at 10:26 AM 0
Share

in that case, Destroy(instanceRocket.gameObject, 3.0);

avatar image
1
Best Answer

Answer by josif · May 20, 2010 at 12:47 AM

call it TimedObjectDestructor.js put the code in a rocket prefab the set it to like 5 or so what ever you want and were its says detach children is if its ticket it will make the rocket last forever so don't tick it unless you need to.

var timeOut = 1.0; var detachChildren = false;

function Awake () { Invoke ("DestroyNow", timeOut); }

function DestroyNow () { if (detachChildren) { transform.DetachChildren (); } DestroyObject (gameObject); }

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

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

Want to shoot to make an explosion 2 Answers

make explosion work 2 Answers

Destroy objects when key is pressed 1 Answer

Missile Collision and Explosions 1 Answer

how to add time ? (how to show a guiTexture and hide it after some time?) 0 Answers


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