Answer the question
In order to leave comments, you need to log in
How can I change the color of a 3d object in animation?
Such a problem. There is a 3d model of the character. I want it to glow red when it takes damage. I wanted to make an animation, but the object does not have the usual 2d Color field.
How to do it?
Answer the question
In order to leave comments, you need to log in
The material must have a _Color field.
You will create a script that will change the color value through "material.SetColor ()" (if I'm not mistaken).
public class MyCode
{
[SerializedField] private Color _color = Color.red;
// Соединяешь материал что используется в MeshRenderer (из ресурсы).
[SerializedField] private Material _mat;
public void TakeDamage()
{
// ...
// блаблабла
// ...
StartCoroutine(ChangeColor());
}
private IEnumerator ChangeColor()
{
float speed = 5;
// Изменение с белого на красный
for(float t = 0; t < 1; t += Time.deltaTime * speed)
{
_mat.SetColor("_Color", Color.Lerp(Color.white, _color, t));
yield return null;
}
// И обратно.
for(float t = 0; t < 1; t += Time.deltaTime * speed)
{
_mat.SetColor("_Color", Color.Lerp(_color, Color.white, t));
yield return null;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question