在我的汽车战争游戏中,汽车转弯时产生了打滑痕迹。 它工作正常,现在过了几秒钟后,我想减小它的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);
}
}
}
仍然,它对我不起作用。
答案 0 :(得分:0)
TrailRenderer
具有一个名为endColor
的属性,您可以设置Color
的alpha,以便该行逐渐淡入结尾。
void Start()
{
Color noAlphaEndColor = line.endColor;
line.endColor = new Color(noAlphaEndColor.r, noAlphaEndColor.g, noAlphaEndColor.b, 0.0f);
}
void Update()
{
if (line.endColor.a < 0.001)
{
Destroy(gameObject);
}
}