Question by
mrsam993 · Jan 04 at 05:53 PM ·
unity 2dcollider2dtilemap
Checking OnCollisionEnter2D names with TilemapCollider2D
I currently have a tilemap set up with three different tiles with three different names, I have a player and I want something different to happen when the player collides with each of the unique tiles. I am currently using this code:
//If collision with gameobject
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name == "Walls_0")
Debug.Log("Walls_0");
else if (col.gameObject.name == "Walls_1")
Debug.Log("Walls_1");
else if (col.gameObject.name == "Walls_2")
Debug.Log("Walls_2");
}
The problem is that the tilemap is getting its collision from a TilemapCollider2D so the code above is only checking the name of the entire tilemap when any collision happens instead of being able to check the name of each individual tile that is being collided with. I'm not sure how to get around this so any ideas would be great thank you!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613051257im_/https://answers.unity.com/themes/thub/images/avi.jpg)