How can I change a tile or tilebase color in unity… There’s no GetComponent function in TileBase and I was wondering if there’s a way. I wanted to have flashing effects on my tiles to make the game more lively; but I dont know how to do that if I don’t know how to change the tile color in Unity. Please help if you can…,
To change a tile’s colour in code you have to access it via a position on a tilemap and flag it to indicate it can change colour.
This is working for me:
/// <summary>
/// Set the colour of a tile.
/// </summary>
/// <param name="colour">The desired colour.</param>
/// <param name="position">The position of the tile.</param>
/// <param name="tilemap">The tilemap the tile belongs to.</param>
private void SetTileColour(Color colour, Vector3Int position, Tilemap tilemap)
{
// Flag the tile, inidicating that it can change colour.
// By default it's set to "Lock Colour".
tilemap.SetTileFlags(position, TileFlags.None);
// Set the colour.
tilemap.SetColor(position, colour);
}
Note that the position passed into SetTileFlags and SetColour uses the tilemap’s local positon to access the tile. So if your tilemap’s not positioned at the origin, you’ll need to adjust accordingly.
In order to change a tile sprite/color you have to access it through the tilemap, specifically the type “Tile”, Tilebase will not have such features.
More info at Unity - Manual: Tile