Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. public float TargetAlpha
  2. {
  3. // TODO: validate on Set (0.f .. 1.f)
  4. get; set;
  5. };
  6.  
  7. void Update() {
  8. Fade();
  9. }
  10.  
  11. void Fade()
  12. {
  13. Color c = renderer.material.color;
  14. if (!Mathf.Approximately(c.a, targetAlpha))
  15. {
  16. // Scaling up or down
  17. // TODO: Move to 'rate' variable?
  18. var alphaAdjust = targetAlpha < c.a ? -.1f : .1f;
  19.  
  20. // Frame rate independence
  21. alphaAdjust *= Time.deltaTime;
  22.  
  23. // TODO: Check potential bug with shifting c.a past target alpha and oscilating, verify if not an issue depending on FPS?
  24.  
  25. c.a += alphaAdjust;
  26. renderer.material.color = c;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement