Set a Tag Multiple GameObject[]

How can i set a tag multiple GameObject
i tried this but its not work.

public GameObject randomSpawnes;

void SetTag(string tag ){

	GameObject[] randomSpawnes = GameObject.FindGameObjectsWithTag (tag);
	foreach (GameObject target in randomSpawnes) 
	{

		target.gameObject.tag ="BlaBla";

	}			

}

Hi.
So you’re trying to re-tag objects that were already tagged ? Or did I understand wrong ?

Anyway, I think your script can’t work because :

  • you declared twice randomSpawnes as an array of GO
  • you never call the SetTag() method which does the tagging.

Your script should be something like that :

public class Retagging : MonoBehaviour {

	public GameObject[] randomSpawnes;

	void Start () {
		SetTag ("blabla", "jobijoba");
	}

	void SetTag (string oldTag, string newTag) {
		randomSpawnes = GameObject.FindGameObjectsWithTag (oldTag);
		foreach (GameObject target in randomSpawnes) {
			target.tag = newTag;
		}            
		Debug.Log (randomSpawnes.Length + " objects found and re-tagged");
	}
}