目录为:Assets/Media/Effect/Script/目录下
SM_TrailFade.cs
using UnityEngine;
using System.Collections;
public class SM_TrailFade: MonoBehaviour
{
public float fadeInTime = 0.1f;
public float stayTime = 1.0f;
public float fadeOutTime = 0.7f;
public TrailRenderer thisTrail = null;
private float timeElapsed = 0.0f;
private float timeElapsedLast = 0.0f;
private float percent;
void Start()
{
thisTrail.material.SetColor ("_TintColor", new Color (0.5f, 0.5f, 0.5f, 1));
if (fadeInTime < 0.01f)
{
fadeInTime = 0.01f;
}
percent = timeElapsed / fadeInTime;
}
void Update()
{
timeElapsed += Time.deltaTime;
//fade in >>>> stay >>>>>> fade out
if (timeElapsed <= fadeInTime)
{
percent = timeElapsed / fadeInTime;
thisTrail.material.setcolr ("_TintColor", new Color (0.5f, 0.5f, 0.5f, percent));
}
if ((timeElapsed > fadeInTime) && (timeElapsed < fadeInTime + stayTime))
{
thisTrail.material.SetColor ("_TintColor", new Color (0.5f, 0.5f, 0.5f, 1));
}
if (timeElapsed >= fadeInTime + stayTime && timeElapsed < fadeInTime + stayTime + fadeOutTime)
{
timeElapsedLast += Time.deltaTime;
percent = 1 - (timeElapsedLast / fadeOutTime);
thisTrail.material.SetColor ("_TintColor", new Color (0.5f, 0.5f, 0.5f, percent));
}
}
}