- Home /
Set reference to multiple gameobjects based on tag category / multiple tags?
Is it possible to set
   gos = GameObject.FindGameObjectsWithTag("player/player1");
so that gos also includes everything under the player/ tag group?
So that it gets player/player1, player/player2, player/player3, player/player4?
Answer by tormentoarmagedoom · Mar 29, 2020 at 02:04 PM
Hello.
First, if you try to set reference to multiple objects, "gos" must be an array or a list.
And for your problem, you should use list, so you can add element to an existing list.
So
 List<GameObject> Players = new List<GameObject>();
 foreach(GameObject ObjectFound in GameObject.FindGameObjectsWithTag("player"))
 {
 Players.Add(ObjectFound );
 }
Do the same foreach again with other tags, and at the end, the list Players will have all the objects.
BYE!!
Answer by sacredgeometry · Mar 29, 2020 at 02:05 PM
The question is why would you need to do this? Nothing is stopping you from maintaining a list or dictionary of GameObjects that you can reference at any time. You dont have to use tags.
You could even leverage a search engine like Lucene if you have a lot of data.
 Something like: https://pastebin.com/Fy6rLTW2 
Your answer
 
 
             Follow this Question
Related Questions
How to find one object in specific layer? 1 Answer
difference between GameObject.FindGameObjectWithTag(Tag tag) and GameObject.FindWithTag(Tag tag) 3 Answers
Destroying Multiple Objects with Tags 1 Answer
Need a Custom array Index to look up gameobject tags? 2 Answers
Changing tagged objects in script 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                
