Advertisement
Guest User

Untitled

a guest
Jul 21st, 2013
1,268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. private float transparency = 1f;
  2. private bool transparencyGoingUp = false;
  3. private bool currentlyFlashing = true;
  4.  
  5. (when the player moves, i set currently flashing to false, meaning the flashing cycle will finish and go back to 1 (filly visible) but not keep flashing)
  6. also excuse the weird condition checks for transparency == 1/0.1. I had issues with it making the float be (ex) 0.09 instead of 0.1, so this way made it work
  7.  
  8. The following coroutine is called every frame (in Update())
  9.  
  10. IEnumerator flashTransparency(float waitTime)
  11. {
  12. //update the alpha (transparency)
  13. Color tempColor = cubee.renderer.material.color;
  14. tempColor.a = transparency;
  15. cubee.renderer.material.color = tempColor;
  16.  
  17. //adjust what the alpha will be updated to next time this coroutine is run
  18. if(transparencyGoingUp)
  19. {
  20. transparency += 0.1f;
  21. if(transparency > 0.95f && transparency < 1.2f && currentlyFlashing) //if(transparency == 1)
  22. transparencyGoingUp = false;
  23. }
  24. else //if transparency is going down
  25. {
  26. transparency -= 0.1f;
  27. if(transparency < 0.2f && transparency > 0.08f) //if(transparency == 0.1f)
  28. transparencyGoingUp = true;
  29. }
  30.  
  31. //wait before calling this again so it isnt called every frame and therefore flash way too fast
  32. yield return new WaitForSeconds(waitTime / 9); // 9 because it updates 9 times per direction, so waitTime == total time to go top to bot or bot to top
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement