- Home /
Getting the position of all game objects with the same tag
Hi !
So, I have a 2D scene which I intend to save in XML using the XML Serializer and was planning who to save and load it.
What I want to do now (away from XML Serializer, in C#) is to get the positions of all game objects in the scene tagged, for example, GrassTile.
Also, I want to delete all the game objects tagged, also for example, SandTile.
How can I do that ?
Thanks in Advance
Answer by Cherno · Dec 30, 2015 at 11:06 AM
Use GameObject.FindGameObjectsWithTag to get an array of the GameObjects. loop through the array to either access their transform.positions individually, or declare a seperate Vector3 array and put the positions in there. Same goes for deleting GameObjects: Loop through the array and delete each element.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Problems with the XML Serializer 1 Answer
C# GameObject Lists 2 Answers
Distribute terrain in zones 3 Answers
What is the most efficient way to spawn objects with probability weights in this scenario? 2 Answers