Get previous Tile layer at runtime

iRhyiku
New Member
Registered: 2017-02-23
Posts: 2

Topic

I have a painting system at run time working using your following code:

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
TileIndex ti = tileFloor.ClosestTileIndexFromRay(ray);

selectedBrush.brush.Paint(tileFloor, ti);

Some tiles I have, I want to check what tile was at that location before the new one gets painted, prefably checking the layer of it.
As I don't want to paint over certain tiles with another tile.

Hope that made sense, thank you!

Last edited by iRhyiku (2017-02-23 20:04:01)

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 1

Hi

You can test for an existing tile by lookup up the tile of interest from the tile system of interest:

// Only paint tile if floor tile is currently empty:
var existingFloorTile = tileFloor.GetTileOrNull(ti);
if (existingFloorTile == null) {
    selectedBrush.brush.Paint(tileFloor, ti);
}

// Only paint tile if wall tile is currently empty:
var existingWallTile = tileWalls.GetTileOrNull(ti);
if (existingWallTile == null) {
    selectedBrush.brush.Paint(tileFloor, ti);
}

I hope that this helps with your question!

iRhyiku
New Member
Registered: 2017-02-23
Posts: 2

Response 2

Thank you!

That certainly put me in the right direction and I got it working perfectly.

The code I used for anyone wanting this in the future:

var existingFloorTile = tileFloor.GetTileOrNull(ti);
 if (existingFloorTile.brush.layer == 13)
 {
  selectedBrush.brush.Paint(tileSprite, ti);
 }

Last edited by iRhyiku (2017-02-24 18:24:02)