Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

change tag

Discussion in 'Scripting' started by Zychew, Nov 25, 2014.

  1. Zychew

    Zychew

    Joined:
    Feb 23, 2014
    Posts:
    6
    hi, i have a simple question in Javascript;

    functionOnMouseDown(){
    var gos : GameObject[];
    gos = GameObject.FindGameObjectsWithTag("fred");

    gos.tag = "untagged"
    }

    how can i make the change to game object with tag "fred", into "untagged"?
     
  2. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    229
    You need to loop through all you objects and assign the new tag for each of them.
    You can't (unless I'm wrong) assign a flag to an array of objects.

    This is c#, but you get the intention.

    Code (csharp):
    1.  
    2. foreach(GameObject go in gos){
    3.      go.tag = "untagged";
    4. }
    5.