Smooth color transition

Imagine, that I have a red box. I want to create a function that will change box’s color from red to blue (for example) in a fixed amount of time. What is the best way to achieve this?

I’ve studied the subject already. For now I have an idea how to do this, but there is one problem. How can I get current values of red, green and blue of the material. For example, the function material.renderer.GetColor(“_Color”) gives me just a string “RGBA(0.561, 0.000, 0.000, 1.000)”. I can create and use a parser script to parse it and retrieve data about red, green and blue. But is there any other easier method?

Thanks.

Ok, I’ve forgot about a very simple structure: renderer.material.color.r (r - for red, “b” and “g” - for blue and green); But still there is no way to find red, green and blue for _SpecColor and _ReflectColor values.

So far I believe, parser is the only way…

Added: I’ve found smth interesting. Function GetColor() returns Color! This means that I can get values in this way:

myMaterial.renderer.material.GetColor("_SpecColor").r
myMaterial.renderer.material.GetColor("_SpecColor").g
myMaterial.renderer.material.GetColor("_SpecColor").b

Can’t you just use the Color struct?

Color myColor = myMaterial.renderer.material.GetColor(“_SpecColor”);

Edit. you can Lerp between 2 Colors.

Use this script.

–Eric

Callahan and Eric, thank you for your answers. I’ve looked through Erics script - it is very functional, but I needed something less complicated for my project. After a while I’ve managed how to use Color.Lerp function and solved my problem.