Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by staraffinity · Feb 10, 2016 at 09:26 PM · guitextfadein

Best way to fade in GUI text in Unity 5.x.x?

I've tried to look around but it seems many of the examples I've found are obsolete in Unity 5?

I got a link to the examples here: http://wiki.unity3d.com/index.php?title=Fade#Examples

This looks like something I could use:

 Fade.use.Alpha(guiTexture, 0.0, 1.0, 5.0, EaseType.In);

But I'm not sure where to put that in my C# script. Can someone assist?

Thanks in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Cherno · Feb 10, 2016 at 10:47 PM

If you indeed use the old GUI system, just change the GUITexture's color's alpha value via Coroutine.

If you use the new UI system, give the parent object of the UI objects that should become transparent a Canvas Group component, and change it's alpha to 1 during runtime via CoRoutine.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image staraffinity · Feb 11, 2016 at 11:00 PM 0
Share

Thanks so much for your reply!

I don't have to use the old GUI system, let's go for the new.

I found the Corutine has an example of ”fade out” (so I would have to do the opposite) in the Unity Documentation: http://docs.unity3d.com/$$anonymous$$anual/Coroutines.html

The example goes:

 IEnumerator Fade() {
     for (float f = 1f; f >= 0; f -= 0.1f) {
         Color c = renderer.material.color;
         c.a = f;
         renderer.material.color = c;
         yield return null;
     }
 }

But I get ”parsing error” when I try to put that into a C# script. Guess I'm putting the code in the wrong place and/or missing some other code that's required.

Would it be too much to ask for an example script of that code snippet above in a working C# script? :-| :) Or maybe there's a better way than doing as the code example above?

avatar image
0

Answer by staraffinity · Feb 16, 2016 at 12:15 AM

Manged to get it to work by attaching this script to the GUI text object:

 using UnityEngine;
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
  
 public class CanvasFadeIn : MonoBehaviour {
     CanvasGroup csGrp;
    
     void Awake(){
         csGrp = GetComponent<CanvasGroup>();
     }
    
     void Start (){
         StartCoroutine("FadeIn");
     }
  
     IEnumerator FadeIn(){
         csGrp.alpha = 0;
         float time = 5f;
        
         while(csGrp.alpha < 1){
             csGrp.alpha += Time.deltaTime / time;
             yield return null;
         }
     }
 }

However, I don't know what that ”csGrp” means? I got the script from elsewhere, not mine from scratch as you could imagine…

Is the ”csGrp” a reference to a specific Canvas Group? Because there can be more than one Canvas Croup in a scene. I don't know of a way to name a Canvas Groups, though – is it possible?

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · Feb 16, 2016 at 01:33 AM 1
Share

yes, csGrp is a reference to a CanvasGroup component. The Awake function assigns the reference by searching for a CanvasGroup component on the gameObject this script is attached to. It will use the first one it finds, but since CanvasGroups are commonly not used in multiples on the same GameObject, that's ok in this case.

avatar image staraffinity Cherno · Feb 17, 2016 at 09:52 PM 0
Share

Okay, great. :) One last thing: Is there an easy way to add a certain amount of delay before the start of the fade? I guess it's just to add some lite code snippet somewhere in the above example. I can of course look for it myself…

avatar image Cherno staraffinity · Feb 17, 2016 at 11:07 PM 1
Share
     void Start (){
              StartCoroutine("FadeIn", 1.5f);
          }
 
 
 
   IEnumerator FadeIn(float delay){
               float t = 0f;
               while(t < delay) {
                        t += Time.deltaTime;
                        yield return null;
               }
              
              csGrp.alpha = 0;
              float time = 5f;
             
              while(csGrp.alpha < 1){
                  csGrp.alpha += Time.deltaTime / time;
                  yield return null;
              }
          }
 

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

When I go inside a collider I want GUI Text to appear, and allow me to press 'e' to swap scenes, but it instantly transports me to the scene. 1 Answer

How to change GUI Text color in a javascript? 1 Answer

can my player collide with more than one objects? 1 Answer

Score wont show 0 Answers

How to create a review of previous updates 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges