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

posted on 2014-11-16 20:22  狗刨学习网  阅读(603)  评论(0编辑  收藏  举报