- Home /
Making screen flash texture when player is damaged
I have this code here:
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);
}
and function to call it: if (Hit){ FlashWhenHit(); }
But it can only do the first fade, i.e. after it shows the texture by changing alpha to 80%, it won't go back to alpha=0 again. (Problem with second Fade?) Can anyone help me?
Comment
Your answer
Follow this Question
Related Questions
Screen flashes red when taking damage 3 Answers
Screen flashes red on damage? 4 Answers
SCREEN SPECIAL EFFECT HELP 1 Answer
GUI Rect appears to give random values 1 Answer
Screen.dpi for in-editor 4 Answers