I’ve finally succeeded in getting my text to fade in and then back out. The problem is that now all my GUItext’s, not just the one that I specify, end up having their alpha changed:
#pragma strict
var thoughtText : GUIText;
var fadeIn :boolean;
var fadeOut :boolean;
var shedSeen :boolean;
function Start () {
thoughtText.font.material.color.a = 0;
fadeIn = false;
fadeOut = false;
shedSeen = false;
}
function OnTriggerEnter (other : Collider) {
if (other.gameObject.name == "Shed Thoughts"){
if (shedSeen == false) {
thoughtText.text = "Oh lord";
Debug.Log("Fade in");
fadeIn = true;
yield WaitForSeconds (5);
Debug.Log("Fade out");
fadeOut = true;
shedSeen = true;
}
}
}
function OnTriggerExit (other : Collider) {
thoughtText.text = "";
}
function FadeIn(){
if(thoughtText.font.material.color.a<1)
thoughtText.font.material.color.a += Time.deltaTime;
else fadeIn = false;
}
function FadeOut(){
if(thoughtText.font.material.color.a >= 0)
thoughtText.font.material.color.a -= Time.deltaTime;
else fadeOut = false;
}
function Update(){
if(fadeIn)FadeIn ();
if(fadeOut)FadeOut ();
}
Any help would be greatly appreciated.
I've pasted the code in your question in order to make it easier to read and answer.
– aldonaletto