- Home /
Making my Text fade in on a trigger
I'm attempting to make some text fade in when the player get's close to specific objects and then after a short amount of time fade away.
I've nearly got it all working, my only problem is that this code is failing miserably. Instead of fully fading in it only fades in a little bit.
Any help would be greatly appreciated. I'm new to Javascript and Unity so please be gentle.
Answer by fafase · Aug 03, 2012 at 04:55 PM
Your issue is simple.
You are using OnTriggerEnter with the fading in. As a result, it is only performed once. You need to create a function that is run if a boolean is true. that boolean is switched in the trigger function.
var fading :boolean;
function Start{
fading = false;
}
function Update(){
if(fading)Fading;
}
function OnTriggerEnter(other:Collider){
if(other.gameObject.tag=="Player")fading = true;
}
function Fading(){
if(thoughtText.font.material.color.a<1)
thoughtText.font.material.color.a += Time.deltaTime;
else fading = false;
}
Answer by Fistch · Aug 04, 2012 at 05:48 PM
I tried out what you suggested and it worked pretty well. Thanks for the help.
Your answer
Follow this Question
Related Questions
Trigger Script Not Firing 4 Answers
Using OnTriggerEnter to change UI text 1 Answer
Fade in text one character at a time 3 Answers
OnTriggerEnter being called twice 1 Answer
Display a Text/GUI on screen when triggerd with Fadein/Fadeout 1 Answer