- Home /
Changing tags of an Object and its Child
I want the sword object and all of its children to change tags, but for some reason it won't work. It's probably some obvious problem and I just don't see it.
function OnMouseUp()
{
var sword = GameObject.FindGameObjectsWithTag("Unequiped");
sword.tag = "Equiped";
}
Answer by rutter · Oct 17, 2013 at 01:03 AM
Note there are two functions to look up GameObjects by tag:
FindWithTag() returns one matching GameObject (returns null if no such object).
FindGameObjectsWithTag() returns an array of matching GameObjects (returns empty array if no such objects).
The way your code is written, you're asking for an array... but then treating it as if it's a single object. If you only need the one object, you can just call FindWithTag()
. If you want to edit every object, you can loop through the array as described here, setting tag
on each object in the array.
Your answer
Follow this Question
Related Questions
Calling 2 objects into script for onCollisionEnter? 1 Answer
How to affect a group of objects. 1 Answer
Find objects by one tag or another. 3 Answers