- Home /
Question by
Matteo · Mar 20, 2011 at 09:20 PM ·
tagfindgameobjectswithtagfindwithtag
GameObject.FindWithTag (problem with multiple objects)
Hi everybody! I've got three objects with the tag "Gear" So why, when I press the arrow keys, does only one object tagged "Gear" rotate? How can I fix that? (Unity 2.6.1)
This is the code
function OnTriggerStay (other : Collider) {
var meccanismo = GameObject.FindWithTag ("Gear");
transform.Rotate( 0, 0, Input.GetAxis("Vertical")*-13*Time.deltaTime);
meccanismo.transform.Rotate(0, 0, Input.GetAxis("Vertical")*-8*Time.deltaTime);
}
Comment
Best Answer
Answer by Eric5h5 · Mar 20, 2011 at 09:31 PM
Look in the docs for FindWithTag: "Returns one active GameObject tagged tag." You would want to use FindGameObjectsWithTag for more than one. That returns an array, so your code still won't work like that. You need to loop through all elements in the array.
Your answer
![](https://koobas.hobune.stream/wayback/20220613113853im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Dummy Child with Tag (for findGameObjectsWithTag) - any caveats? 1 Answer
Find with tag problem 1 Answer
Question about "FindGameObjectsWithTag" 1 Answer
Destroy gameobject by tag (.js) 3 Answers