I was wondering if it is possible to fade one colour to another. My scene consists of a GUI to change the actual colour of the material and a 3D-Object with that material applied to. Pressing a button changes the color from lets say red to white. The code looks like this:
The variable “Lack_mat” represents the main material of my 3D-Object.
Can anyone please shed some light on if and how this can be done?
Thanks in advance.
You could also use the Animator to do it, if you know how to use it.
Just go into its Material property, add a key at the beginning, and a key at the time you want it to end, and drag the second key to where you want the end fade color to be. The grid works as the left hand side is the value, and the top is the timeframe (based on framerate).
Not getting this to work so far. I have tried to use Eric’s script but only received instancing errors so far. Maybe there is an other way to solve this but at the moment my head is smoking. Giving it another try tomorrow.
ok. I’ve read the directions and gave it a try with a new scene with just a cube, a light and a camera. Works as expected. Then I tried to define more complex colors than just red or green using variables which works fine, too. But I fail telling the Cubes Material to change its colors to the ones I’ve defined in the variables. The script won’t accept my variable “Color_old” and gives me a “Color_old is not a member of UnityEngine.Color” error. My second problem will probably be that I want to change the color of a material which is used by a number of objects in my original scene. Your script uses the renderer attached to an object to change its color. Can I somehow use a material instead?
This is my actual script (which is attached to the cube):