GUI.Label not fading...

OK, well I’m trying to show a bonus score when a player hits something with a missile, but this code below is not fading… it does work to show the score and then disappear after a few seconds though… any quick things I’m missing? I know it must be simple.

I’ve snipped this from elsewhere and modified for my purpose -

function OnGUI () {
if(showscore){
GUI.color = color;
GUI.Label(Rect(Screen.width / 2 - 100, Screen.height / 2, 600, 100), "BONUS +" + bonus,bonusstyle);
Fade();
}
}			


function Fade(){
color = Color.black;
yield WaitForSeconds (2);
 while (color.a > 0)
   { 
    color.a -= Time.deltaTime;
    yield;     
   }
   showscore=false;
				}

You’re calling the Fade function every frame from OnGUI as long as “showscore” is true. You should call the function only once.

–Eric

Ahhh, thanks Eric! Funny I missed that… code blindness I suppose! :slight_smile: Added this below… all peachy now! :slight_smile:

if (trig){
Fade();
trig=false;