- Home /
How to fade in GUI text.
So I have a few GUI.Label, and a few GUI.Styles to go with them. Since there are a few different ones to each there own settings. So how can I fade these labels in? I know the most simple way is to adjust the alpha. I did this before on fading a character renderer. I tried this with the text and the alpha isn't accessing anything. Saying used as a property but can't because its a type. Can someone write a simple line of code to show me how to do this correctly please?
Answer by podmaster · Nov 06, 2014 at 12:47 AM
Sorry i have updated my unity to the new UI 4.6 so i don't remember exactly how to do it but you should first get the Gui text component then acces the color alpha.
 var GuiLabel : GUIText;
 
 GuiLabel.color.a = yourValue;
 
 //OR
 
 SomeGameObject.GetComponent(GUIText).color.a = yourValue;
If you are getting an error post it and post your code.
its not a gui text component. its a scripted GUI.Label
Answer by Ozzyel-PT · Nov 06, 2014 at 06:30 AM
 public float alpha = 1.0f;
 public float fadeSpeed = 2.0f;
 void OnGUI()
 {
 
         if(GUI.Button(new Rect(Screen.width/2, Screen.Height/2, 200, 50))
          {
            StartCoroutine(Fade());
          }
         GUI.color = new Color(255, 255, 255, alpha);// adjust alpha value
         GUI.Label(new Rect(0, 0, 200, 50), "Label");
         //All elements to fade
         GUI.color = new Color(255, 255, 255, 1); // sets it back to 1 for another elements
 }
 IEnumerator Fade()
 {
     alpha = 0;
     while (alpha < 1f)
     {
         alpha += Time.deltaTime*fadeSpeed;
         yield return null;
     }
 }
Your answer
 
 
             Follow this Question
Related Questions
Easy fade in/out on level load/end? 2 Answers
Fade In and out when level is loaded 2 Answers
Fade 3d text with lerp? 1 Answer
GUI Label/Text Area Doesn't Show Up Inside Scrollview 1 Answer
Disable component via script 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                