Browse Source

Improved Camera fade wait logic

Early out if already at target alpha
master
chrisgregan 11 years ago
parent
commit
5092e82eee
  1. 20
      Assets/Fungus/Scripts/CameraController.cs

20
Assets/Fungus/Scripts/CameraController.cs

@ -62,15 +62,23 @@ namespace Fungus
float startAlpha = Game.GetInstance().fadeAlpha;
float timer = 0;
while (timer < fadeDuration)
// If already at the target alpha then complete immediately
if (startAlpha == targetAlpha)
{
float t = timer / fadeDuration;
timer += Time.deltaTime;
yield return null;
}
else
{
while (timer < fadeDuration)
{
float t = timer / fadeDuration;
timer += Time.deltaTime;
t = Mathf.Clamp01(t);
t = Mathf.Clamp01(t);
Game.GetInstance().fadeAlpha = Mathf.Lerp(startAlpha, targetAlpha, t);
yield return null;
Game.GetInstance().fadeAlpha = Mathf.Lerp(startAlpha, targetAlpha, t);
yield return null;
}
}
Game.GetInstance().fadeAlpha = targetAlpha;

Loading…
Cancel
Save