Unity 脚本修改方块透明度使其有一个渐变效果
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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); } }