- Home /
Change color of individual tile in tilemap
I'm trying to change the color of an individual tile when I put my mouse on it, but I can't get the color to change.
I can only seem to change the color of all tiles within the map by using tilemap.color = Color.x
Here's what I have
public Tilemap tiles;
Tilemap tMap;
private void Awake()
{
tMap = GetComponent<Tilemap>();
control = FindObjectOfType<GameController>();
}
private void OnMouseOver()
{
Vector3 mousePos = Input.mousePosition;
Vector3Int cellPosition = tiles.WorldToCell(Camera.main.ScreenToWorldPoint(mousePos));
Tile tile = tMap.GetTile<Tile>(cellPosition);
if (control.money >= control.currentTowerCost)
{
tile.color = Color.green;
//tMap.color = Color.green;
}
else
{
tile.color = Color.red;
//tMap.color = Color.red;
}
}
Comment
Your answer
Follow this Question
Related Questions
How do I add neighbor rules for RuleTiles by script? 1 Answer
TileMap won't show up in 2d object in heirarchy. 0 Answers
Getting the Collider of a Tile 0 Answers
Removing tile on tilemap1 removes tile from tilemap2. How can i fix this? 0 Answers
Unity crashes when erasing tiles on a tilemap and entering those empty tiles. 0 Answers