- Home /
How to create fading (In and Out) GUI text in Unity 5
Hi! I am currently working on a project and ran into a problem that regards a function I need throughout the game. I was looking for a sort of GUI Text that pops up throughout the game, mostly for dialogue or natural message purposes (In game screenshot below) but I currently couldn't find any solutions on the forums. Most of them require a box collider with a trigger which is understandable, but never seems to work on my character. Also many other tutorials don't come to much help as they are outdated and don't work properly on Unity 5. If there is a simpler solution for pop up GUI text in unity 5, id be very thankful if I could get some help. If you can help, here is a reference to what I am trying to recreate on my character.. https://youtu.be/ikrJqlBr1gI?t=6m36s
(Basically the text that fades in and out when the protagonist speaks as well as the messages that guide the player on what to do or where to go) Many thanks :)
Cant you just adjust the Alpha value of the colour of the UI Text-Box?
Answer by KdRWaylander · Jul 17, 2015 at 03:00 PM
Hi,
You can use animations (and an animator) to modify the alpha of your text.
Or add a canvas group component and modify its alpha value (and all the objects you add to this group will fade the same way)
Answer by Positive7 · Jul 17, 2015 at 03:43 PM
Could you perhaps give an example to where those example code snipets you linked to should be placed in a Unity C# script? I get parsing errors… :(
Where are you finding the alpha on a canvas? I'm trying to fade multiple images on/off over a short time say 0.2sec to 0.5sec with the click of a button, but neither my images or canvas have any sort of alpha option...
Answer by Nick_Rizzo · Feb 10, 2016 at 02:54 PM
This is very simple all you have to do is add the canvas group component to the text, then you will add the ANIMATION (Not animator unless you want to) component to the object, then create an animation and change the alpha to zero or what ever number you want at about 2 seconds in or however long you want it to fade for. You can then create a script like this and put it on the gameObject. "For c# just change function to void"
function OnTriggerEnter ()
{
gameObject.GetComponent.<Animation>().Play("name of animation");
}
Answer by Jjules · Feb 10, 2017 at 03:39 AM
This is actually very simple! Just make a canvas group, get a local reference to it (using UnityEngine.UI, public CanvasGroup cg, maybe cg = GetComponent< CanvasGroup>()), and SmoothDamp the alpha of the CanvasGroup (cg.alpha = Mathf.Smoothdamp(cg.alpha, 1 to fade in/0 to fade out, ref referenceVariable, fadeTime)
Thanks! I really wish they would have made all the UI elements have an Alpha ins$$anonymous$$d of just specific ones... Didn't realize CanvasGroup would have an alpha and not the normal canvas or image UI.
No problem! SmoothDamp needs a variable it can play with to do the smoothing calculations. Its the equivalent of giving you a sheet of scratch paper to solve a math equation. The reference variable is the SmoothDamp's scratch paper. Just make a variable, do absolutely nothing to it, and feed in ref [variableName] in SmoothDamp so it can mess with it is all
Your answer
![](https://koobas.hobune.stream/wayback/20220611231655im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I start fading out text upon setting it? 3 Answers
Fading a text gui style 3 Answers
Having proper text areas in unity? 0 Answers
I cant read the file i wrote, unless i reload it in VS. 1 Answer
Can TextMesh support multiline text? 1 Answer