【发布时间】:2020-01-17 04:08:27
【问题描述】:
我正在尝试制作“湿脚印”,但在重复使用该步骤时遇到了一些淡出颜色并将其重置为起始颜色的问题。我有一个带有几个脚步游戏对象的游戏对象数组,当它接触地面时,它们被放置在玩家脚的位置上。它目前正在汇集这些步骤,一切正常。因为我想尽可能保持轻量级,所以我正在使用带有属性块的贴花着色器,并且我需要在放置对象时淡出 _MainColor 属性,并且当在不同位置再次使用同一个对象时,它需要重置.然而,问题是褪色在其当前设置中不起作用。当前发生的情况是,在重复使用时颜色会重置为黑色,并且假设会再次淡出,但它只是立即再次透明。
void Update()
{
if (lastPos != transform.position)
{
stepPositioner = true;
lastPos = transform.position;
//Debug.Log("This Go changed position: ", this);
}
if (stepPositioner)
{
StartCoroutine(FadeTimer());
}
}
IEnumerator FadeTimer()
{
_renderer.GetPropertyBlock(_propertyBlock);
_propertyBlock.SetColor("_MainColor", startColor);
_renderer.SetPropertyBlock(_propertyBlock);
yield return new WaitForSeconds(1);
_renderer.GetPropertyBlock(_propertyBlock);
_propertyBlock.SetColor("_MainColor", Color.Lerp(startColor, endColor, Time.time * .5f));
_renderer.SetPropertyBlock(_propertyBlock);
stepPositioner = false;
}
【问题讨论】: