How to change another object's Tag
Hi!
Just wanted to know how to change the tag of an object via another object. All I'm able to do is to change the tag of the object who has the script.
In my example, I want to always have the first bone in my array to get the tag "FirstBone".
if (checkBones.Length > 0) {
firstBone = checkBones [0];
transform.gameObject.tag = "FirstBone";
if (bonesTaken == false) {
target = firstBone.transform.position;
agent.SetDestination (target);
}
}
Comment
Best Answer
Answer by Fredex8 · Mar 31, 2016 at 06:57 PM
Assuming firstBone and checkBones[0] are GameObjects then all you need to do is:
firstBone.tag = "FirstBone";
Or if you wanted to set them directly from the array:
checkBones[0].tag = "FirstBone";
checkBones[1].tag = "SecondBone";
checkBones[2].tag = "ThirdBone";
Any time you start a line with transform.
or gameObject.
like that you are only going to be affecting the object which has the script on it.
wow can't understand how it was that simple and I did not find it. Thanks a lot!