I’m making a simple level editor for a 2D platformer. When I delete (Destroy()) a tile in the level editor, then try to recalculate the textures for my tile stitching, the remaining tiles behave as if the destroyed tile were still in the scene.
//Delete the (topmost) object at the mouse position
void DeleteObject() {
Collider2D hit = Physics2D.OverlapCircle(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0.0001f, menuMask);
if (hit != null) {
if (hit.gameObject.GetComponent<Tile>() != null) {
Destroy(hit.gameObject);
Recalculate();
}
}
}
void Recalculate() {
Tile[] tiles = FindObjectsOfType<Tile>();
foreach (Tile t in tiles) {
t.RecalculateTexture();
}
}
In the above code, “hit.gameObject” is included in the array “tiles” after being destroyed, and the other tiles in “tiles” don’t re-stitch themselves properly as a result. What do I need to do differently to destroy the hit tile completely before Recalculate() is called?