Question by
sid4 · Oct 22, 2016 at 10:28 PM ·
guitexture
Help my gui code wont work i want screen to flash red
javascript 2d game and hers my code please edit and help I know its close. do I add a gui texture and add this to the gui texture?
#pragma strict
var red : GUITexture :
function Fade (start : float, end : float, length : float, currentObject : GameObject) { //define Fade parmeters
if (currentObject.GetComponent.<GUITexture>().color.a == start){
for (i = 0.0; i < 1.0; i += Time.deltaTime*(1/length)) { //for the length of time
currentObject.GetComponent.<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.GetComponent.<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, GUITexturered);
yield WaitForSeconds (.01);
Fade (0.8, 0, 0.5, GUITexturered);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612095232im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Moving GUI Label through key board? 1 Answer
Edit 2D Texture and apply to canvas 0 Answers
Remove or Add Blank Images to GUI.DrawTexture in Unity 3D 1 Answer
GUITEXT and Texture 0 Answers