1.首先创建一个GUIText对象。
2.在Project面板中新建一个C#脚本命名为FadingMessage,双击该脚本进行编辑,添加如下代码。
using UnityEngine;
using System.Collections;
public class FadingMessage : MonoBehaviour
{
float DURATION = 2.5f;
// Update is called once per frame
void Update()
{
if (Time.time > DURATION)
{
Destroy(gameObject);
}
//guiText.text = Time.time.ToString();
Color newColor = guiText.material.color;
float proportion = (Time.time / DURATION);
newColor.a = Mathf.Lerp(1, 0, proportion);
guiText.material.color = newColor;
}