Created
September 26, 2017 04:39
-
-
Save vikhik/d2b72a15c1b9dc75e70266cdca1404ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public float TargetAlpha | |
{ | |
// TODO: validate on Set (0.f .. 1.f) | |
get; set; | |
}; | |
void Update() { | |
Fade(); | |
} | |
void Fade() | |
{ | |
Color c = renderer.material.color; | |
if (!Mathf.Approximately(c.a, targetAlpha)) | |
{ | |
// Scaling up or down | |
// TODO: Move to 'rate' variable? | |
var alphaAdjust = targetAlpha < c.a ? -.1f : .1f; | |
// Frame rate independence | |
alphaAdjust *= Time.deltaTime; | |
// TODO: Check potential bug with shifting c.a past target alpha and oscilating, verify if not an issue depending on FPS? | |
c.a += alphaAdjust; | |
renderer.material.color = c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment