Transitioning 3 colors depending on int value.
Hello. I would like to implement this behaviour on my game: I have a green cube and I want it changing its color depending on the heat it has. Heat is an int variable that will have values between 0 and 200 (for example), and this is the color transition that I would like to achieve:
0-100: green becoming red. 100-200: red becoming black.
What I don't know how to achieve is the effect of mixing colors taking into account the heat. I have tried using material alpha but the result is not what I am looking for, neither are lerps as I don't want transitions in time.
Thank you very much.
Answer by Hellium · Aug 30, 2019 at 06:14 PM
public Gradient Gradient;
public Material Material;
public int MaxHeat = 200;
public void SetColor(int heat)
{
Material.color = Gradient.Evaluate((float)heat / MaxHeat);
}
Tested and working perfectly for what I need! Thank you very much for que quick answer and your help.
Your answer
![](https://koobas.hobune.stream/wayback/20220612211448im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to change the color of cube using vr gaze 0 Answers
How To change a Text Object's Color Randomly using Color 32? 2 Answers
Please Help With Script 1 Answer
Issue with if-statements requiring two conditions. 1 Answer
Continuing a Dialogue 0 Answers