Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //redTime is a floating point value that represents how long the overlay should stay on the screen
- //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
- // in the function when the player takes damage
- // flash screen red to let player know they are being hit
- 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
- redTime = (float)damage / 50.0f; // at 100 damage, the red will take 2 seconds to completely disappear.
- // in the update function (runs every frame)
- if (redTime > 0.0f)
- {
- // fade out the red overlay.
- redTime -= Time.deltaTime;
- redOverlay.color = new Color(redOverlay.color.r, redOverlay.color.g, redOverlay.color.b, 1.0f * redTime);
- }
- else
- {
- redOverlay.color = new Color(redOverlay.color.r, redOverlay.color.g, redOverlay.color.b, 0.0f); // make sure it's gone
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement