Unity 脚本修改方块透明度使其有一个渐变效果

using UnityEngine;
using System.Collections;

public class TestClass : MonoBehaviour
{
    private float AlphaValue = 1.0f;
    private float time = 0.0f;
    private bool state = false;

    Material material;
    private void Start()
    {
        material = GameObject.Find("YourGameObject").GetComponent<Renderer>().material;
    }
    void Update()
    {

        time += Time.deltaTime;
        if (time > 0.2f)
        {
            state = true;
            time = 0;
        }
        if (state)
        {
            AlphaValue -= 0.001f;

        }

        material.color = new Color(1f, 1f, 1, AlphaValue);

        print(AlphaValue);
    }
}
View Code

 

posted @ 2024-06-17 15:26  朋丶Peng  阅读(1)  评论(0编辑  收藏  举报