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 Bob1 · Sep 02, 2011 at 08:24 PM · destroydelay

Delayed Destroy Clone Not Working

I'm relatively new to Unity, and my shooting script is not working. I'm planning to shoot (instantiate a sphere) then destroy the sphere 5 seconds later. Without the following script, I can shoot, but the spheres will stay on screen. With it, or the Destroy(gameObject, float) on the instantiated sphere, the sphere is destroyed as soon as it is instantiated. Please help.

Here's the code:

if(Input.GetButtonDown("Shoot1"))

{ var OffsetCenter = transform.position + center; var instancesphere = Instantiate(sphere, OffsetCenter, transform.rotation); instancesphere.rigidbody.AddForce(transform.forward * sphereforce);

Destroy(instancesphere.gameObject, 5);

}

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 SisterKy · Sep 02, 2011 at 08:34 PM 1
Share

please format your code (edit -> select the code -> hit the 1010101 button); also, please don't use 'unity' as a tag (everything's about unity here... I fixed them)

avatar image Bob1 · Sep 02, 2011 at 08:45 PM 0
Share

oh sorry

avatar image Waz · Sep 02, 2011 at 09:57 PM 0
Share

Still not formatted. Sister$$anonymous$$y only fixed your tags for you (to get the unique Goddess of The Tags badge, which will be awarded to the first person to change more tag sets than there are Questions ;-)

avatar image SisterKy · Sep 02, 2011 at 10:08 PM 0
Share

Oooh... drools in her lap ... but I'll have to settle for 'Saint of Tags', as 'Goddess' goes against my religious believes ;)

2 Replies

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

Answer by Hendrys · Sep 02, 2011 at 08:54 PM

Simply add a new Script to the bullet prefab, and write on the Awake function:

 Destroy(gameObject, 5);
Comment
Add comment · Show 6 · 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 SisterKy · Sep 02, 2011 at 08:59 PM 0
Share

If I'm not mistaken he tried that already...?

avatar image Bob1 · Sep 02, 2011 at 09:02 PM 0
Share

That did the trick! Thanks! I had it all wrong in function update().

avatar image SisterKy · Sep 02, 2011 at 09:08 PM 0
Share

well, I guess that makes this the right answer. please click the 'accept' button (little green checkmark topleft of this answer)

avatar image Hendrys · Sep 02, 2011 at 09:15 PM 0
Share

Ok you are welcome ^^ , please mark it as the right answer.

avatar image Waz · Sep 02, 2011 at 10:02 PM 0
Share

This can't be the answer, it will destroy the object doing the instantiating.

Show more comments
avatar image
0

Answer by SisterKy · Sep 02, 2011 at 08:34 PM

http://unity3d.com/support/documentation/ScriptReference/WaitForSeconds.html should do what you want...? Greetz, Ky.

Comment
Add comment · Show 3 · 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 Bob1 · Sep 02, 2011 at 08:44 PM 0
Share

I removed my script component from the bullet and it shoots well, but the debugger keeps on saying "Can't Destroy Transform component. If you want to destroy the game object please call 'Destroy' on the gameobject ins$$anonymous$$d." I'm not sure how to do that in this case.

avatar image SisterKy · Sep 02, 2011 at 08:58 PM 1
Share

hrm... if you remove this script (which does destroy the gameObject, not the transform), but get this error that almost sounds like this script is not the problem but you have a Destroy() somewhere else. If you click on the error it should take you to the problematic code. Or if it doesn't for some reason, it's also telling you what path and file the error is at, as well as which line and column it's in...?

avatar image Bob1 · Sep 02, 2011 at 09:02 PM 0
Share

it seems that I wrongly put the script on the bullet with function update(). The problem's fixed now. Thanks though!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is Destroy(this.gameObject) not working immediately? 2 Answers

How can i get this Delay script to work? 1 Answer

How to create object falling from sky CONTINUOUSLY 1 Answer

Delay "Destroy(gameObject)" 2 Answers

destroy object after a delay? 6 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