- Home /
Fade In _TintColor Over Time
Hello,
I have a game object that has a material attached to it. The material is a Particles/Alpha Bleneded, and by default, the Tint Color Alpha is set to 0.
What I want to be able to do, is to increase the Tint Color Alpha over time. Any ideas?
I've tried doing something like this:
var increase = 0;
var color : Color = Color(0.5, 0.5, 0.5, increase);
renderer.material.SetColor ("_TintColor", color);
for(var i = 0; i < 10; i++){
increase = increase + 0.05;
yield WaitForSeconds(0.01);
}
But nothing happens. Please help!
Thanks
Answer by Lo0NuhtiK · Jan 22, 2012 at 05:34 AM
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) ;
}
Time.time is the time since the game started -- so this only works in the 1st 20 seconds. Add a startTime variable: alpha=(Time.time-startTime)/secondsToFade);
In this case, don't really need the Lerp (a lerp turns a 0-1 into a different range, like 50 to 80.)
@Owen Reynolds - Works well, but how would I add in specific color start - to end values? For example: increase the red from 0.5, to 1, over time? Thanks
This only happens once. Is there a way to process the code more than once?
If you look at Loonkut's(sp) answer, the 0 and 1 in Lerp are the stop and start. You could extend that to use vars: if(Time.time<startTime+secondsToFade) Lerp(startVal, endVal, percentFormula);
Whenever you want to go, set startTime to now, and startVal/endVal to whatever. It even works to fade from 1 to 0.
Answer by .sanders · Jan 22, 2012 at 04:52 AM
I suggest using iTween which takes care of such thing for you:
http://itween.pixelplacement.com/index.php
It's pretty powerful and free to use... Read the documentation on how to use it. I think you might want to check on the ColorTo method.
hope this is useful
cheers!
Your answer
Follow this Question
Related Questions
Fade out a line renderer? 1 Answer
Make a tilemap brighter/tint it white 0 Answers
Color tint on a shader. 1 Answer