30 lines
726 B
C#
30 lines
726 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class GhostItem : MonoBehaviour
|
|
{
|
|
//持续时间
|
|
public float duration;
|
|
//销毁时间
|
|
public float deleteTime;
|
|
|
|
public MeshRenderer meshRenderer;
|
|
|
|
void Update()
|
|
{
|
|
float tempTime = deleteTime - Time.time;
|
|
if (tempTime <= 0)
|
|
{ //到时间就销毁
|
|
GameObject.Destroy(this.gameObject);
|
|
}
|
|
else if (meshRenderer.material)
|
|
{
|
|
float rate = tempTime / duration; //计算生命周期的比例
|
|
// Color cal = meshRenderer.material.GetColor("_Color");
|
|
// cal.a *= rate; //设置透明通道
|
|
// meshRenderer.material.SetColor("_Color", cal);
|
|
}
|
|
|
|
}
|
|
}
|