Question by
Jesus-Cryses · Aug 15, 2020 at 11:33 AM ·
colortilemapcolor changetiles
How to get a fluid color transition for every tile in a tilemap?
Hello, I want to change the color for every Tile in a Tilemap. But I want to change it with the Color.Lerp function, so I get a fluid color change for every Tile at the same Time.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class ColorChange : MonoBehaviour
{
public Tilemap tilemap;
[SerializeField] [Range(0f, 1f)] float speed;
private Color startColor;
[SerializeField] Color endColor;
float timer = 100f;
bool act = false;
void Update()
{
if(timer>0)
timer -= 1f;
if(timer==0 && !act)
{
act = true;
foreach (var position in tilemap.cellBounds.allPositionsWithin)
{
startColor = tilemap.GetColor(position);
tilemap.SetTileFlags(position, TileFlags.None);
tilemap.SetColor(position, Color.Lerp(startColor, endColor, speed));
}
}
}
}
I know that the tilemap.Set Color function changes the tiles color instantly. But maybe someone know a way how I can accomplish a fluid color transition.
Comment
Your answer
Follow this Question
Related Questions
Why is the tilemap color change messed up? 0 Answers
Color.Lerp over HP 1 Answer
Tile script: Check if TileMap is a palette or not? 0 Answers
Saving data of multiple instances of object? 0 Answers
How to destroy a tile on collision in several parts 0 Answers