Hello, all! I am writing a script that allows you to set parameters for the time you would like a guitexture to stay dormant, then fade in, then stay constant, then fade out.
I would just like to know how to calculate this:
After the number of dormant seconds has been reached, I would like to calculate the rate at which an object needs to fade in and how to make a fluid transition independent of frames.
For instance, if the FadeinTime variable is set to 4.0 seconds, I would like to take the guitexture’s alpha from 0 to 100 in 4.0 seconds, but instead of updating every second, I’d like to update it as quickly as possible at a set rate.
How would I do this?
Thanks for the help! (And I will release the script when I finish) - YA
IEnumerator Fade(material mat, float duration, Color start, Color end)
{ // remember the start
float start = Time.time;
do
{ // calculate how far through we are
float elapsed = Time.time - start;
float normalisedTime = Mathf.Clamp(elapsed / duration, 0, 1);
mat.color = Color.Lerp(start, end, normalisedTime);
// wait for the next frame
yield return null;
}
while(elapsed < duration);
}