Question: I have problem with add dynamically `tag` to `gameObejcts` , when I `Instantiate` an `enemy` I add enemy tag using this:

```
GameObject temp = (GameObject)Instantiate(enemy, spwanPosition, spwanRotation);
temp.gameObject.tag = "Enemy";

```

I read this from : [Is it possible create a tag programmatically](http://answers.unity3d.com/questions/33597/is-it-possible-to-create-a-tag-programmatically.html)

but when I try to Destroy this object with specific `explosion` There is no object with `Enemy` tag:

```
void OnTriggerEnter(Collider other)
{
    if (other.tag == "Boundary")
    {
        return;
    }
    if (other.tag == "Enemy")
    {
        Debug.Log("enemy");   # Never printed in console
        Instantiate(enemyExplosion, other.transform.position, other.transform.rotation);
    }
    Instantiate(explosion, this.transform.position, this.transform.rotation);
    Destroy(other.gameObject);
    Destroy(this.gameObject);

```

How can I add a tag dynamically to a `gameObject` that `Instantiate` multiple times?

**Edit**

This is the Picture from Instantiated enemy Object in Paused game , It is so wired , it has `Enemy tag` , But why this didn't work?

[![enter image description here](https://i.stack.imgur.com/XbPiz.jpg)](https://i.stack.imgur.com/XbPiz.jpg)

The problem is when in run-time `Enemy` tag is assigned to objects but when I check `if(other.tag == "Enemy")` this dosen't work!

Answer: 
The link that you posted is about creating tags dynamically, you don't need this and I don't see why anyone would need to do this.

I presume you have a tag named Enemy in the tag manager?

You are instantiating an enemy prefab, which means you don't need `enemy.tag = "Enemy"`. Just set the enemy prefab tag to Enemy in the inspector.

This will instantiate the new enemies with the same values as the prefab.

As for the trigger not working, I am not sure, make sure you have met all the specifications for the enemy calling the OnTriggerEnter().

Taken from <http://answers.unity3d.com/questions/753481/ontriggerenter-not-working-tried-everything-c.html>

> 
> OnTriggerEnter, at least one of them has to have the Is Trigger property checked and at least one of them has to have a Rigid Body. If neither of your objects is a Trigger, you can use OnCollisionEnter instead.
> 
> 
> Once that's all set, you should check the Layers (not Tags) on your objects. To edit which Layers collide with each other, you can look at Edit -> Project Settings -> Physics.
> 
> 
>
I suspect that your problem is not the tag, but the collision. Does your enemy object have a collider? Does a simple collision test succeed?

Edit (forget about this):

Actually your problem might be that you shouldn't use `other.tag` but `other.gameObject.tag`.