I'm creating a 2d game and I want to make it so that tiles are destructible whenever a projectile collides with a tile, the problem is I don't know how to get the tile that the projectile is colliding with, I would like to make it so that it area of damage.
However for now I want to make it so that once the projectile reaches the ground it destroys the tile it's sitting on I've made a collider2d to help me with that but I still have no idea how to get the tile that's the projectile is sitting on.
IEnumerator OnCollisionEnter2D(Collision2D x)
{
Vector2 hit = gameObject.transform.position;
Debug.Log("y" + hit.y);
hit.y =- 3; // What y should i put here in order to make sure its the same as the tile the projectile is sitting on
if (x.gameObject.tag != "Player")
{
Collider2D[] collidedwith = Physics2D.OverlapCircleAll(this.gameObject.transform.position, radius);
tilemap.SetTile(tilemap.WorldToCell(hit), null);
}
A screenshot for better explanation (I would like to get rid of the blue tile):