Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
1
Question by jvt619 · Dec 18, 2013 at 03:21 PM · destroygameobjectschildrendeleteclones

Deleting all child clones in a GameObject

Like the picture below. How can I delete/destroy all of the Particle(clones) in those GameObjects when I press the "F" button ?

alt text

Event Flow: If I click those "GameObj" the "Particle(Clone)" will appear and then if I press the "F" button those clones must/should be deleted/destroyed

Comment
Add comment · Show 3
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 Bunny83 · Dec 18, 2013 at 03:25 PM 2
Share

Well, it's great to have this image which helps to understand your problem, however there are somethings that aren't clear at all.

  1. What "event" should destroy those gameobjects? Think about your event flow. What happens --> what should happen.

  2. Where are scripts attached which could do this job? On each "GameOgj"? or maybe on a higher parent (if there is any)?

avatar image jvt619 · Dec 18, 2013 at 03:39 PM 0
Share

Event Flow: If I click those "GameObj" the "Particle(Clone)" will appear and t hen if I press the "F" button those clones must be deleted/destroyed

avatar image Bunny83 · Dec 18, 2013 at 07:46 PM 0
Share

Uhm, thanks for the Update, but my second point is still unanswered. I guess you have the "click and create the particle effect" woring. $$anonymous$$y question was how you do this. Where is the script / the scripts attached to? Anyway i'll post a possible answer.

1 Reply

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

Answer by Bunny83 · Dec 18, 2013 at 07:53 PM

You could do something like that:

 // C#
 public class SomeObject : MonoBehaviour
 {
     public Transform particleEffect;
     void OnMouseDown()
     {
         var clone = (Transform)Instantiate(particleEffect);
         clone.parent = transform;
         clone.localPosition = Vector3.zero;
         clone.localEulerAngles = Vector3.zero;
     }
     void Update()
     {
         if(Input.GetKey(KeyCode.F))
         {
             for(int i = transform.childCount-1; i>=0; i--)
                 Destroy(transform.GetChild(i).gameObject);
         }
     }
 
 }

Attach this script to all of your "GameObj". If you have a different way of creating the particle effects, please include your script in your question.

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 jvt619 · Dec 19, 2013 at 12:48 AM 0
Share

thanks for the answer. $$anonymous$$anage to delete all of the child clones using your loop method

avatar image $$anonymous$$ · Jan 14, 2017 at 09:25 PM 0
Share

Thank you for this, been looking everywhere and couldn't find a solution.

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

19 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 avatar image

Related Questions

how do you destroy a texture2d array ? 3 Answers

How to destroy GameObject when clicked on. 2 Answers

Detect when GameObject has been deleted / removed from scene 10 Answers

finding and destroying specific children 1 Answer

Destroy all previous clones. 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