如何在Unity中實現文字的漸隱效果?

歡迎來到unity學習unity培訓unity企業培訓教育專區,這裏有很多U3D資源U3D培訓視頻U3D教程U3D常見問題U3D項目源碼,我們致力於打造業內unity3d培訓、學習第一品牌。

 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;
 
}

更多精彩請點擊 http://www.gopedu.com/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章