I am then using SetTile`SetTile to add a new texture on z-axis 1 in a grid (this is me dragging out a rectangular area of tiles while holding down a mouse button) Each frame, it removes the old tiles on z-axis 1 and replaces them with a new grid of tiles.
selectionArea = new RectInt(selectionArea.x, selectionArea.y,
selectedTile.x - selectionArea.x,
selectedTile.y - selectionArea.y);
var selectionAreaPos = GetPositiveRect(selectionArea);
var lastSelectionPos = GetPositiveRect(lastSelection);
Debug.Log($"Pos: {selectionAreaPos} // {lastSelectionPos}");
for (int x = lastSelectionPos.x; x <= lastSelectionPos.x + lastSelectionPos.width; x++)
{
for (int y = lastSelectionPos.y; y <= lastSelectionPos.y + lastSelectionPos.height; y++)
{
tileMap.SetTile(new Vector3Int(x, y, 1), null);
}
}
// this is here just to show I have used both a for loop and BoxFill when attempting to get this to function
//for (int x = selectionAreaPos.x; x <= selectionAreaPos.x + selectionAreaPos.width; x++)
//{
// for (int y = selectionAreaPos.y; y <= selectionAreaPos.y + selectionAreaPos.height; y++)
// {
// tileMap.SetTile(new Vector3Int(x, y, 1), (buttonDown == 1 ? tiletest1 : tiletest2));
// }
//}
tileMap.BoxFill(new Vector3Int(selectedTile.x, selectedTile.y, 1),
(buttonDown == 1 ? tiletest1 : tiletest2),
selectionAreaPos.x, selectionAreaPos.y,
selectionAreaPos.x + selectionAreaPos.width,
selectionAreaPos.y + selectionAreaPos.height);
selectionArea = new RectInt(selectionArea.x, selectionArea.y, selectedTile.x - selectionArea.x, selectedTile.y - selectionArea.y);
var selectionAreaPos = GetPositiveRect(selectionArea);
var lastSelectionPos = GetPositiveRect(lastSelection);
for (int x = lastSelectionPos.x; x <= lastSelectionPos.x + lastSelectionPos.width; x++)
{
for (int y = lastSelectionPos.y; y <= lastSelectionPos.y + lastSelectionPos.height; y++)
{
tileMap.SetTile(new Vector3Int(x, y, 1), null);
}
}
for (int x = selectionAreaPos.x; x <= selectionAreaPos.x + selectionAreaPos.width; x++)
{
for (int y = selectionAreaPos.y; y <= selectionAreaPos.y + selectionAreaPos.height; y++)
{
tileMap.SetTile(new Vector3Int(x, y, 0), (buttonDown == 1 ? tiletest1 : tiletest2));
}
}
My guess so far is this is due to me declaring the TileBaseTileBase tiles as:
I'm currently thinking maybe each tile needs to be its own instance, though I'm not sure how. But this may be down to me wanting to use the grid system for a player map editor rather than a fixed editor in unityUnity.
edit:
Here'sHere's the Tilemap & grid components as set up in the inspector.



