如何在Unity中實現文字的漸隱效果?
阿新 • • 發佈:2019-01-21
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;
}