Screen flashes red when taking damage

How would I make the screen flash red whenever the player takes damage?

A simple method:

Make fullscreen GUITexture, and set it to red. Set the opacity to 0%, and attach it to a separate camera on a layer above the main camera (so it is drawn on top of everything). Make sure you set the clear flag on this camera to Don't clear.

Set up your logic so whenever your player is hit, a variable is set to true momentarily.

Attach a script to the GUITexture that looks at the state of the hit variable, and if it is true, set the opacity of the GUITexture to 80% for a few frames and then back to 0% (this will give you the flash but also allow the player to still see the action on screen).

Fading a GUITexture is pretty easy:

function Fade (start : float, end : float, length : float, currentObject : GameObject) { //define Fade parmeters
if (currentObject.guiTexture.color.a == start){

for (i = 0.0; i < 1.0; i += Time.deltaTime*(1/length)) { //for the length of time
currentObject.guiTexture.color.a = Mathf.Lerp(start, end, i); //lerp the value of the transparency from the start value to the end value in equal increments
yield;
currentObject.guiTexture.color.a = end; // ensure the fade is completely finished (because lerp doesn't always end on an exact value)
        } //end for

} //end if

} //end Fade

function FlashWhenHit (){
    Fade (0, 0.8, 0.5, GUITextureobjectname);
    yield WaitForSeconds (.01);
    Fade (0.8, 0, 0.5, GUITextureobjectname);
    }

Then, when wou want you screen to flash, just call FlashWhenHit:

if (Hit){
FlashWhenHit();
}

The above example (in FlashWhenHit) will fade your texture from 100% transparent (invisible) to 80% opaque (just slightly transparent) over 1/2 second. It checks to make sure the texture is 100% transparent before attempting the fade to eliminate visual errors, and at the end ensures it is at exactly 80% opacity. It will then wait 1/100th second, and fade the texture back out to transparent. You can, of course, adjust the starting and ending opacity by changing the start and end values in the function call, as well as how long the fade takes and what object if affects. The WaitForSeconds is in there so the texture will stay at its max opacity momentarily (to make it more visually obvious); the length of time is adjustable there too. Also, if you want the screen to flash a certain number of times, you could use a for loop with a counter that goes to 0 from, say, 3, to get the screen to flash 3 times, etc.

Hope this helps.

To show the red screen continuously instead of just instantly (for example when you are inside the fire zone and receives consistent burning damage), the fading of the opacity should be put in the update() function and changes in every frame. The following code may help in this situation.

bool increment = true;
	float len = 0.5f;
	float opac = 0.4f;
	bool alarm;
	
	// Update is called once per frame
	void Update () {

		if (alarm)
		{		
			aColor = gameObject.guiTexture.color;
			if (increment == true) 
			{	
				aColor.a += opac*Time.deltaTime/len;

			} else
			{
				aColor.a -= opac*Time.deltaTime/len;
			}

			if (aColor.a > opac) 
			{
				increment = false;
			} else if (aColor.a < 0f)
			{
				increment = true;
			}

			gameObject.guiTexture.color = aColor;
		}
	}

When you want to start the consistent flashing screen, just set the variable ‘alarm’ to true. And whenever you want to stop this flashing, set the ‘alarm’ to be false, and also reset the opacity to 0.

Posted a possible solution here: Screen flashes red on damage? - Unity Answers