I am working with Unity and I have a Tilemap filled with tiles. At a given point in time, I create a Collider2D in the scene with a specified width and height. What I need to do is obtain the list of tiles within the Tilemap that are overlapped by the Collider2D object that I just created.
Collider2D[] results = new Collidear2D[16];
int count = rb2d.OverlapCollider(contactFilter, results);
for (int i = 0; i < count; i++)
{
Collider2D result = results*;*
Tilemap breakableMap = result.gameObject.GetComponent();
breakableMap.SetTile(breakableMap.WorldToCell(…), null);
}
With the above code, I can determine the Collider2D objects that I am overlapping. However, in order to remove a tile from the Tilemap, I need an actual Vector3 coordinate that indicates some point of contact between the region of overlap between the two colliders.
My question is, in regards to this question, is this current approach the ideal approach? If so, what can be done to easily retrieve the coordinate of the overlapped tile so that it can be removed?