Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
4
Question by JBoy · Feb 01, 2012 at 07:04 AM · objectdestroydelaywaitseconds

destroy object after a delay?

How do i destroy object after a delay?

Comment
Add comment · Show 4
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 JBoy · Feb 01, 2012 at 11:13 PM 0
Share

Thanks All!

avatar image Bunny83 · Feb 01, 2012 at 11:16 PM 1
Share

@JBoy: don't post comments as answers. Answers should exclusively be used to answer the question. Read the FAQs for more information.

I've converted your answer into a comment.

avatar image RangerOfTheRings · Apr 19, 2017 at 06:22 PM 0
Share

can you destroy a object after standing on it?

avatar image Bryangs RangerOfTheRings · Apr 19, 2017 at 09:30 PM 0
Share

Yes, but you should really ask that yourself or search before just commenting on an old post. By doing that you are "resurrecting" an old question that is already 5 YEARS old, and making a new question that has been asked soon be replaced by it. You see, i just had to post again just to warn you...

6 Replies

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

Answer by BiG · Feb 01, 2012 at 07:07 AM

It's easy:

Define a function like this:

 var delay = 2.0; //This implies a delay of 2 seconds.
 
 function WaitAndDestroy(){
    yield WaitForSeconds(delay);
    Destroy (gameObject);
 }

Call this function when you want to destroy it.

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
27

Answer by MP2fps · Feb 01, 2012 at 07:08 AM

var destroyTime = 5; function Update () { Destroy(gameObject, destroyTime); }

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 asafsitner · Feb 01, 2012 at 08:52 AM 1
Share

This.

The Destroy(); method has the functionality you are looking for integrated already. Just use the above overload and you're good to go.

avatar image Guppie1337 · Jan 14, 2015 at 12:25 PM 0
Share

I should have realized this through the Scripting API. I'd thumbs up but can't yet. Thanks.

avatar image
18

Answer by wrobel221 · Dec 05, 2013 at 07:05 PM

You can just set time delay in Destroy method

 Object.Destroy(gameObject, 2.0f);

Here's the method description

 static void Destroy(Object obj, float t = 0.0F);


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 petrucio · Mar 12, 2015 at 08:01 AM 0
Share

Thanks! Very useful when you want to destroy a gameobject outside of a $$anonymous$$onoBehaviour script, with no coroutine access. And the code is cleaner even when you do have coroutine access.

avatar image
2

Answer by fafase · Feb 01, 2012 at 07:06 AM

All is there http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html

Hope that helps

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
1

Answer by Wiebren-de-Haan · Nov 22, 2012 at 08:49 PM

 var Seconds = 10;
 
 function Update(){
     Destroy();
 }
 
 function Destroy(){
     yield WaitForSeconds(Seconds);
     Destroy(gameObject);
 }

Add this to a javascript, set the time in Seconds (Use the var). And the gameobject will be destroyed after in this script 10 seconds

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 Coffee-with-Venky · Jul 30, 2014 at 03:26 PM 0
Share

will you provide this in c#

avatar image Calum1015 · Mar 16, 2015 at 05:40 PM 0
Share

I know this is a late comment @Coffee with Venky, but all you would have to do in order to convert it would be to change the "function's" with "void's" and "var Seconds = 10" to "public float Seconds;"

  • 1
  • 2
  • ›

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

16 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

Related Questions

Dispose Object in IOS 0 Answers

How to create object falling from sky CONTINUOUSLY 1 Answer

audio.Play ignoring WaitForSeconds 2 Answers

Destroy the current GameObject? 7 Answers

Can't proceed next level when the object destroy not complete. 2 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