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 krotana · Aug 03, 2011 at 03:33 PM · arraydestroyfunctionitems

How to destroy all the items with one function?

How do I destroy all the items with a tag?

I have looked at things but I am not exactly sure what I am doing wrong or what I have to do.

They are "cubes" coming at you. and I want the game to restart and delete all the cubes comming at you. The cubes are tagged as badCubes

I tried using:

var badCubesarray[] = GameObject.FindGameObjectsWithTag ("badCubes"); for (var badCubes in badCubesarray[]) { Destroy("badCubes" in badCubesarray); }

or

var badCubesvar = GameObject.FindGameObjectsWithTag ("badCubes"); for (var badCubes in badCubesvar) { Destroy("badCubes" in allBadCubes); }

I understand the logic is to create an array variable, add all the objects of that tag to it, and then create a for all the objects with that tag to destroy. But what exactly do I have to write?

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 krotana · Aug 04, 2011 at 02:59 AM

after a little bit of headake, I made it work! that and I finished the game on time for an assignment

 var array : GameObject[] = GameObject.FindGameObjectsWithTag("taggedCubes");
 var item : GameObject;
     
     for (item in array)
     {
     Destroy(item);
     }
 }

My game for you fellas to check on, the cubes disapear when the game is restarted.

http://raws.adc.rmit.edu.au/~s3281341/dim2_assignment1/heroCube.html

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 Eric5h5 · Aug 04, 2011 at 04:35 AM 0
Share

Well, you posted a comment as an answer and didn't accept/vote up the answer that helped you (I guess that would be $$anonymous$$e). *sigh* As an aside, the iterator in a for/in loop doesn't exist outside the loop, so the "var item: GameObject;" line of code is completely irrelevant and should be removed. In other words, you have two different variables called "item" and one of them is unused.

avatar image krotana · Aug 04, 2011 at 09:44 AM 0
Share

This code does work however, if you play my game with the given link, once you "restart" the game all the cubes disappear.

What the var is doing, for every "GameObject" one by one, delete.

How otherwise would you write the code?

avatar image krotana · Aug 04, 2011 at 09:47 AM 0
Share

A number of different sources helped me with this problem. But who really helped me is a programmer friend from my course. He explained to me step by step and sent me to the correct links and places to look at.

avatar image
0

Answer by Eric5h5 · Aug 03, 2011 at 06:14 PM

"Destroy("badCubes" in badCubesarray);" isn't correct syntax. It's just "`Destroy(badCubes);`".

(Since you seem to be new here: Please format code using the code button, don't post comments as answers, and remember to accept/vote up answers that help you. Thanks!)

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 Waz · Aug 03, 2011 at 08:43 PM 1
Share

And if you name the variable badCube, the logic may be clearer to you.

avatar image krotana · Aug 04, 2011 at 03:01 AM 0
Share

thanks Eric and yea, I'll do that!!!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how do you delete variables or arrays? 3 Answers

Parenting an instantiated prefab. 1 Answer

Calling functions from a class - Curious issue 1 Answer

Instantiate same PreFab to an array of GameObject by RayCast. 1 Answer

How can I check if ALL items in an array/list meet a condition? 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