OnTriggerEnter2D is not finding my tag. I have a tagged a Prefab spawning objects.

void OnTriggerEnter2D(Collider2D col){
Debug.Log (“enter collider”);

	if (gameObject.tag == "obstac") {
		Debug.Log ("destroy");
		Destroy (this.gameObject);



it’s not going i could see “enter collider” but not “destroy”

This is because you are checking the gameobjects own tag instead of the tag of your collider. Change line 4 to this:

if (col.gameObject.Tag == "obstac")

The problem is that the parameter 'col’ that you spent in Collider2D:

OnTriggerEnter2D (Collider2D col)

you’re not using to get the collided object:

if (gameObject.tag == “obstac”)

To solve this problem you have to tell Unity:

if (col.gameObject.tag == “obstac”)

Good luck and I hope you work, and it will do :slight_smile:

First, check to see if the tag you have matches the one being used. I’m guessing the tag you meant is “obstacle”, but you have “obstac”. Which object do you want to destroy and which one needs the tag? I’m assuming that when the object collides with an obstacle it is destroyed. If that is the case then in your if statement your conditional should be if(col.gameObject.tag == "Obstacle")and your destroy statement should be Destroy (gameObject); as this isn’t required here. I hope this helps!

your looking at the wrong variable,

first get the game object the collider is attached to:

var other = col.gameObject;

then check that game object’s tag:

if (other.tag = "obstac"){