- Home /
QUIText Fade In?
I use this code for QUIText to fade out:
#pragma strict
var color : Color;
function Start(){
color = Color.white;
}
function Update(){
Fade();
}
function Fade(){
while (guiText.material.color.a > 0){
guiText.material.color.a -= 0.1 * Time.deltaTime * 0.05;
yield;
}
}
How do i make it fade in instead of out?
Thanks For Help!
Answer by MrSoad · Dec 10, 2014 at 12:44 AM
You are on the right track richyrich but remember that color values are between 0 and 1 in scripting (not 0 - 255 as in a color picker).
captainkrisu the Fade() function in the script above is being called every frame by Update(), so having a while loop seems very odd. You would use a loop if this was a coroutine that was activated once with the yield having an associated time value to slow the Fade process down.
Something like this will work(this will fade in and out repeatedly) :
#pragma strict
public var MyGUIText : GUIText;
private var fFade_In_Speed : float;
function Start() {
fFade_In_Speed = 0.2;
InvokeRepeating("Fade", 0, fFade_In_Speed);
}
function Fade() {
if (MyGUIText.material.color.a >= 0) {
MyGUIText.material.color.a -= 0.05;
} else {
MyGUIText.material.color.a = 0.0;
CancelInvoke("Fade");
InvokeRepeating("Fade_In", 0, fFade_In_Speed);
}
}
function Fade_In() {
if (MyGUIText.material.color.a <= 1) {
MyGUIText.material.color.a += 0.05;
} else {
MyGUIText.material.color.a = 1.0;
CancelInvoke("Fade_In");
InvokeRepeating("Fade", 0, fFade_In_Speed);
}
}
Place this on the GUIText object. Then drag the GUIText object from the hierarchy window into the MyGUIText var box.
Oh yes, that worked nice! "Video About It" Thank you!
Your answer
![](https://koobas.hobune.stream/wayback/20220613173631im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fade out a line renderer? 1 Answer
Color lerp once? 2 Answers
How to change the alpha element of particles/additive color? 1 Answer
How to vertex colour a single instance of a GameObject? 1 Answer
Desaturating view after each level 2 Answers