Advertisement
Guest User

Untitled

a guest
Dec 21st, 2019
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. //redTime is a floating point value that represents how long the overlay should stay on the screen
  2. //redOverlay is a texture that is constantly painted over the top of the screen on the UI layer, but underneath all the UI elements, normally it has 0 alpha so it does not display
  3.  
  4. // in the function when the player takes damage
  5. // flash screen red to let player know they are being hit
  6. redOverlay.color = new Color(redOverlay.color.r, redOverlay.color.g, redOverlay.color.b, (float)damage / 100.0f); // with 100 damage, red will be 100% alpha
  7. redTime = (float)damage / 50.0f; // at 100 damage, the red will take 2 seconds to completely disappear.
  8.  
  9. // in the update function (runs every frame)
  10. if (redTime > 0.0f)
  11. {
  12.     // fade out the red overlay.
  13.     redTime -= Time.deltaTime;
  14.     redOverlay.color = new Color(redOverlay.color.r, redOverlay.color.g, redOverlay.color.b, 1.0f * redTime);
  15. }
  16. else
  17. {
  18.     redOverlay.color = new Color(redOverlay.color.r, redOverlay.color.g, redOverlay.color.b, 0.0f); // make sure it's gone
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement