using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class StainBehaviour : MonoBehaviour { const float StainLifetime = 2.0f; private float Lifetime = 0f; private Image StainImage; // Start is called before the first frame update void Start() { StainImage = gameObject.GetComponent(); Debug.Assert(StainImage != null); } // Update is called once per frame void Update() { if (Lifetime > StainLifetime) { Destroy(gameObject); } else { StainImage.color = new Color(1f, 1f, 1f, (StainLifetime - Lifetime) / StainLifetime); Lifetime += Time.deltaTime; } } }