Hello, I've been doing research on how to write a script to fade my UI Text i have in a Unity Scene. However, everything i find is related to the old Unity <GUIText>. If someone could help me figure out how to write a new script for UI or point me in a direction that would be great! Here is an old GUI text fade script i found while following tutorials, its irrelevant now i assume with unity 5.x Code (CSharp): using UnityEngine; using System.Collections; public class UIfadeOutText : MonoBehaviour { const float period = 4.0f; void Update () { if(Time.time > period) { Destroy(gameObject); } Color colorOfObject = GetComponent<GUIText>().material.color; float prop = (Time.time / period); colorOfObject.a = Mathf.Lerp(1, 0, prop); GetComponent<GUIText>().material.color = colorOfObject; } }
Not too much to change. Code (CSharp): using UnityEngine; using UnityEngine.UI;//Added this using System.Collections; public class UIfadeOutText : MonoBehaviour { const float period = 4.0f; void Update () { if(Time.time > period) { Destroy(gameObject); } Color colorOfObject = GetComponent<Text>().color;//Changed this float prop = (Time.time / period); colorOfObject.a = Mathf.Lerp(1, 0, prop); GetComponent<Text>().color = colorOfObject;//Changed this } }
ahhh, i see the whole reason i couldn't figure out how to change the UI text was because i wasn't including the unity UI engine library... I literally wrote 4 source codes wondering WTH am i doing wrong. Thanks so much for responding Chris!.