在我的汽车战争游戏中,我在汽车转弯时产生了打滑痕迹。
它工作正常,几秒钟后,我想减少它的alpha值并将其从游戏中移除。我用轨迹渲染器生成了滑痕。
-
我需要为材质指定什么材质球?
-
我怎样才能降低它的α?
目前,我已经使用了这种轨迹渲染器材质:
现在为了逐渐减少alpha,我有这样的代码:
private IEnumerator Start()
{
Material myMaterial = GetComponent<Renderer>().material;
while (true)
{
yield return new WaitForSeconds(1f);
// check whether this skid trail has finished
// (the Wheel script sets the parent to null when the skid finishes)
if (transform.parent.name == "SkidTrailsDetachedParent")
{
// set the start colour
//Color startCol = GetComponent<Renderer>().material.color;
//Color startCol = myMaterial.GetColor("_EmisColor");
Color startCol = myMaterial.GetColor("_TintColor");
// wait for the persist time
yield return new WaitForSeconds(persistTime);
float t = Time.time;
// fade out the skid mark
while (Time.time < t + fadeDuration)
{
float i = Mathf.InverseLerp(t, t + fadeDuration, Time.time);
//myMaterial.color = startCol * new Color(1, 1, 1, 1 - i);
//myMaterial.SetColor("_EmisColor", startCol * new Color(1f, 1f, 1f, 1f - i));
myMaterial.SetColor("_TintColor", startCol * new Color(1f, 1f, 1f, 1f - i));
yield return null;
}
// the object has faded and is now done so destroy it
Destroy(gameObject);
}
}
}
不过,这对我不起作用。