- Home /
FindGameObjectsWithTag works only to first tagged
Hi! I'm makin a house editor for my website.
I am trying to change the texture of all walls of the house by pressing a button.
Look what I've done:
if (GUI.Button (new Rect (260,520,70,70), texparede[1])) {
for (var wall:GameObject in GameObject.FindGameObjectsWithTag("wall")) {
wall.gameObject.transform.Find("parede").renderer.material.mainTexture=texparede[1];
}
}
It isn't working!
It works only for the first wall i created to my house. How can i do to change the texture of alllll GameObjects Found With Tag =="wall" ?? ???
P.S.:The "parede" is an object which can be found inside the tagged as wall, it's where the texture is applied. Thanks!
Thanks for help!
Regards. Henry
Answer by Loius · Oct 15, 2010 at 03:55 PM
"Find" finds the first object named "parede". Which is always the same one.
You can make it search particular hierarchies by name, but a better way would be to nab the object some other way - either by attaching a tag script to it a la
class Parede { }
and then using .GetComponent(Parede), or by storing a reference to the parede in its Wall-tagged object.
Thanks i simplified a little. I used the tag only in the parede not in the gameobject i m using to positionate them. i used in Wall>parede
Thank u! it's working now :D
Are you sure .Find
finds always the same "first" object? I'm under the impression those Find methods don't follow any particular order.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075814im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Swapping a tag for string not working, replacing a tag with a public string, help. 1 Answer
find GUIText 1 Answer
making Enemy detecting script unlimited 0 Answers
Get a total count of gameobjects with the same tag and change level if score reaches max score! 0 Answers
How to make my function only search for objects in the same axis? Code included... 1 Answer