Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement