Hi

I want my screen to show red when player gets hit or damaged. I found some answers online but they didn't seem complete.

    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);
    }

Here is the code. I am not sure what to put under GUITextureobjectname? Also, where do I attache the GUITexture, on the player?

Thanks for any help.

Sorry I don't have time to explain this... Just add a red texture, and through a script call "Fade Out"

    var fadeOutTexture : Texture2D;
var fadeSpeed = 0.3;

var drawDepth = -1000;

//--------------------------------------------------------------------
//                       Private variables
//--------------------------------------------------------------------

private var alpha = 1.0; 

private var fadeDir = -1;

//--------------------------------------------------------------------
//                       Runtime functions
//--------------------------------------------------------------------

function OnGUI(){

    alpha += fadeDir * fadeSpeed * Time.deltaTime;  
    alpha = Mathf.Clamp01(alpha);   

    GUI.color.a = alpha;

    GUI.depth = drawDepth;

    GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);
}

//--------------------------------------------------------------------

//--------------------------------------------------------------------

//--------------------------------------------------------------------

function fadeOut(){
    fadeDir = 1;    
    yield WaitForSeconds (0.5);
    fadeDir = -1;
}

You don't attach the GUITexture to anything, just have it be somewhere in the scene. For GUITextureobjectname you use a reference to the GUITexture. i.e., "var myTexture : GUITexture;"