- Home /
FadeIn color material not working?
Hi,
i don't understand how to fade in the color of a simple cube, like with the code from this page (http://answers.unity3d.com/questions/208544/fade-in-tintcolor-over-time.html)
var color : Color ;
var secondsToFade : float = 20 ;
var red : float = 0.5 ;
var green : float = 0.5 ;
var blue : float = 0.5 ;
var alpha : float = 0 ;
function Update(){
color = Color(red, green, blue, alpha) ;
alpha = Mathf.Lerp(0, 1, Time.time / secondsToFade) ;
renderer.material.SetColor("_TintColor" , color) ;
}
Edit: i have also tried this :
function Start () {
// Set specular shader
renderer.material.shader = Shader.Find ("Specular");
// Set red specular highlights
renderer.material.SetColor ("_SpecColor", Color.red);
}
function Update(){
color = Color(red, green, blue, alpha) ;
alpha = Mathf.Lerp(0, 1, Time.time / secondsToFade) ;
renderer.material.SetColor("_TintColor" , Color.black) ;//color
}
It does not work with my example. In the properties, the Color parameter seems to be loading something, but the material color never changes (the script is linked to the cube). Would anyone know why?
Thanks
Are you sure "_TintColor" is a parameter of your shader? If not, your fading something that has no effect and that would be your problem.
thanks Benproductions1 for the answer, i understand now, Cheers
Answer by Berenger · Feb 01, 2013 at 12:35 PM
That shadder isn't transparent, so fading the alpha won't do anything. Change the shader, or lerp between a startColor and endColor. And make sure there is a _TintColor parameter in your shader.