如何在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/


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