单击按键“A”(随意改变),可以控制GUIText马上显示出来,然后淡出;按住按键“A”,可以使GUIText淡入,如果抬起按键则淡出。
|
|
|
|
|
01 |
var fadeSpeed :float=0.5;//透明度变化的速度 |
|
02 |
privatevar StartTime :float=1;//最开始的等待时间 |
|
03 |
privatevar timeLeft:float=0.5;//流逝的时间 |
|
04 |
function Awake (){ |
|
05 |
timeLeft = fadeSpeed; |
|
06 |
} |
|
07 |
function Update (){ |
|
08 |
if(StartTime >0){ |
|
09 |
StartTime = StartTime −Time.deltaTime; |
|
10 |
}else{ |
|
11 |
if(Input.GetKey(KeyCode.A)){//随便定义一个按键 |
|
12 |
fade(***e); |
|
13 |
}else{ |
|
14 |
fade(false); |
|
15 |
} |
|
16 |
} |
|
17 |
} |
|
18 |
function fade(direction:boolean){ |
|
19 |
var alpha; |
|
20 |
if(direction){ |
|
21 |
if(guiText.material.color.a<1){ |
|
22 |
timeLeft = timeLeft − Time.deltaTime; |
|
23 |
alpha =(timeLeft/fadeSpeed);//利用时间的比例来确定阿尔法的值 |
|
24 |
guiText.material.color.a=1−alpha; |
|
25 |
}else{ |
|
26 |
timeLeft = fadeSpeed; |
|
27 |
} |
|
28 |
}else{ |
|
29 |
if(guiText.material.color.a>0){ |
|
30 |
timeLeft = timeLeft − Time.deltaTime; |
|
31 |
alpha =(timeLeft/fadeSpeed); |
|
32 |
guiText.material.color.a=alpha; |
|
33 |
}else{ |
|
34 |
timeLeft = fadeSpeed; |
|
35 |
} |
|
36 |
} |
|
37 |
} |