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?
That's not a good idea, because then you're drawing an alpha texture over the screen all the time, regardless of whether the screen should be flashing or not (which means potentially big fill-rate hit depending on hardware).
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;"
That's not a good idea, because then you're drawing an alpha texture over the screen all the time, regardless of whether the screen should be flashing or not (which means potentially big fill-rate hit depending on hardware).
– Eric5h5