Instantiate prefab with different tag

Is it possible to instantiate same prefab but with different tag based on position in game. Like if prefab(clone) x position is between 0 and 64 it would have tag “first”, prefab(clone) between 64 and 128 would have tag “second”…

I’m using for loop for instantiating prefabs. It just instantiate cubes one beside other (128* 16) length and width.

Some tips on how could I achive that if it is even possible would be appreciated.

sure, you can access a prefab after you instantiate it by setting it’s value to another gameobject

var clone : GameObject; //you don't need to asign this to anything in the inspector

for(var i = 0; i < 128; i++){ //i'm assuming this is how you are doing it, if not just apply the clone accessing to your code

          if(i < 65){
                    clone = Instatantiate(prefab, Vector3(0,0,0), Quaternion.Identity
                    clone.tag = "first"
          if(i > 64){
                    clone = Instatantiate(prefab, Vector3(0,0,0), Quaternion.Identity
                    clone.tag = "second"


this give sort of an example of what you want to do, except that person wanted to get a component while you just wanted to change the tags of the object

good luck!

Just assign the tag at runtime. Something like:

   var go : GameObject = Instantiate(prefab, pos, Quaternion.identity);

   if (pos.x < 64) { 
       go.tag = "first";
   else if (pos.x < 128) {
       go.tag = "second";
   else {
       go.tag = "third";

Note your position values sound like they might be screen positions. If so, you’ll need to convert the world position for the instantiate into a screen position using Camera.WorldToScreenPoint().

Remember that you can change the tag of Game Objects during runtime.

 public GameObject newPrefab;
    public GameObject prefab;
    void Start(){
    newPrefab = (GameObject)Instantiate (prefab, transform.position, Quaternion.identity);
    newPrefab.tag = "NewTag";

You can do gameObject.tag or change prefab(clone) name

	gm = Instantiate(prefab, prefab.transform.position, Quaternion.identity);
	gm.tag = "second";