using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> /// 弹痕的生命周期 /// </summary> public class BulletHole : MonoBehaviour { private float lifeTime = 50f;//弹痕停留时间 private float colorTime=30f;//30秒后弹痕的颜色慢慢的变浅最后消失 private float timeCounter = 0; void Update () { timeCounter += Time.deltaTime; if (timeCounter >= lifeTime) { //弹痕的颜色慢慢的变浅最后消失 this.GetComponent<MeshRenderer>().material.color = Color.Lerp(this.GetComponent<MeshRenderer>().material.color,Color.clear,colorTime * Time.deltaTime); } if (timeCounter >= 31)//31秒后删除弹痕 { Destroy(gameObject); timeCounter = 0; } } }