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 rebelarcher · Apr 08, 2018 at 11:09 AM · spawntagmultiple objects

find and destroy Multpile GameObject[] tag.

I have a random spawner and I have 7 objects and each object has a tag. I want destroy same objects with tag. I use a sign with 7 objects and another 7 objects is spawned. Those are has same tag. How can i destroy spawned objects according to sign? Sorry for bad english. i hope it's will enough for understood.

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

Answer by poisoned_banana · Apr 08, 2018 at 04:22 PM

 public void DestroyAllWithTag(string tag){ 
     GameObject[] objects = GameObject.FindGameObjectsWithTag(tag);
     foreach(GameObject obj in objects){
         Destroy(obj);
     }
 }
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 rebelarcher · Apr 08, 2018 at 04:40 PM 0
Share

I don't want destroy all. I just want destroy spawned objects according to sign. For example. if sign is red. I want destroy just red objects. or sign is blue just destroy the blue.

avatar image rebelarcher · Apr 09, 2018 at 02:48 PM 0
Share

Simply, if the resulting objects have the same tag as the indicator, I want to destroy them.

avatar image Harinezumi rebelarcher · Apr 09, 2018 at 03:00 PM 0
Share

This function is fine for your purpose, just pass to it the desired tag to be destroyed specified by your sign. For example, when you hit the red sign, you call DestroyAllWithTag("red") (assu$$anonymous$$g that red objects all have the tag "red").
If this is unclear, or not what you want, then please give more details about your project, what kind of game you are making, how it works, and what you want to achieve.

avatar image
0

Answer by rebelarcher · Apr 09, 2018 at 03:27 PM

alt text


qweqwe.png (78.0 kB)
Comment
Add comment · Show 5 · 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 rebelarcher · Apr 09, 2018 at 03:29 PM 0
Share

green object is my sign and its random spawn in there between 7 colors. And other spawned objects is like enemies. if sign is green i just want destroy green enemies.

avatar image Ali-hatem rebelarcher · Apr 09, 2018 at 04:25 PM 0
Share

@poisoned_banana method is fine just call it when you spawn the sign :

 spawn(sign_object); // or show us your spawning code
 DestroyAllWithTag(sign_object.tag);

avatar image rebelarcher Ali-hatem · Apr 09, 2018 at 04:32 PM 0
Share

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Spawn : $$anonymous$$onoBehaviour { public GameObject[]enemies; public Vector3 spawnValues; public float spawnWait; public float spawn$$anonymous$$ostWait; public float spawnLeastWait; public int startWait; public bool stop;

 int randEnemy;


     void Start () {
     StartCoroutine (waitSpawner ());
 
 }


      void Update () {
     spawnWait = Random.Range (spawnLeastWait, spawn$$anonymous$$ostWait);

 }


  IEnumerator waitSpawner(){
     yield return new WaitForSeconds (startWait);
     while (!stop) {
     
         randEnemy = Random.Range (0, 7);
         Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), 1 ,Random.Range(-spawnValues.z, spawnValues.z));
         Instantiate(enemies[randEnemy],spawnPosition + transform.TransformPoint(0, 0, 0), gameObject.transform.rotation);
         yield return new WaitForSeconds (spawnWait);
     


     }
 
 }



}

Show more comments

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

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

Related Questions

How can i destroy multiple objects with tag? 2 Answers

Destroy Enemies With Tag/Color/Name according a indicator. 0 Answers

How to use tag for all players in the Instantiate. 0 Answers

i have a 2d infinite runner game and I want to get the position of the nearest platform so I could respawn the player there. 0 Answers

Object Pickup and Respawn unity 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