- Home /
Changing tagged objects in script
Hello everyone! I would like for multiple objects tags to be changed when I click a separate object. For some reason it won't work
#pragma strict
function OnMouseUp () {
var weapon = GameObject.FindGameObjectsWithTag ("Unequiped");
renderer.enabled = true;
}
Answer by william9518 · Oct 11, 2013 at 01:38 AM
It won't work because you didn't even try to change the tags. All you did is set the weapon variable to a list of GameObjects that have the tag "Unequiped". In order to then change the tags for all these unequiped, add a loop. Since you are using JS, I will provide an answer in JS. For the loop, you should use...
for(var wep : GameObject in weapon){
wep.tag = "TAG YOU WANT TO SET TO";
}
If you cannot understand what I wrote, I suggest going into tutorials about programming and loops.
I'm sorry. I accidentally posted the wrong code. This is what I meant to post.
function On$$anonymous$$ouseUp () {
var weapon = GameObject.FindGameObjectsWithTag ("Unequiped");
weapon.transform.tag = "Equiped";
}
It is because the tag variable is stored inside a GameObject, not a Transform. Just write what I have provided you above. Also, you are not iterating over the different GOs INSIDE your weapon WHICH IS A LIST.
Your answer
Follow this Question
Related Questions
Carrying Objects OnMouseOver 0 Answers
Find and store gameObjects in a array 2 Answers
How to find one object in specific layer? 1 Answer
Find child of a Game Object using tag 4 Answers