我发现了类似的问题,但无法通过提供的答案解决我的问题。
我有以下代码,应该在数组的颜色之间淡入淡出。
public static IEnumerator FadeMaterialColors(Material m, Color[] colors, float speed, ProgressCurve type){
for (int i = 0; i < colors.Length; i++){
yield return (FadeMaterialColorTo(m, colors[i%2], speed, type));
}
yield return null;
}
public static IEnumerator FadeMaterialColorTo(Material m, Color target, float duration, ProgressCurve type){
Color start = m.color;
float y, t = Time.time;
float progress = (Time.time - t)/duration;
while (progress < 1f){
y = GetProgressCurve(progress, type);
m.color = start + y*(target - start);
yield return null; // return here next frame
progress = (Time.time - t)/duration;
}
m.color = target;
}
函数“ FadeMaterialColorTo”本身工作正常,但使用顶部函数调用时却看不到任何结果...我尝试将第3行中的收益下降以获取“ return(FadeMaterialColorTo(m,colors [i%2],速度,类型));” 但是然后我得到以下错误:
Cannot implicitly convert type `System.Collections.IEnumerator' to `bool'
这是一个类似的主题,但是在Unity中,返回类型IEnumerator>不起作用
The non-generic type `System.Collections.IEnumerator' cannot be used with the type arguments
我相信你想要的是这样的:
public static IEnumerator FadeMaterialColors(Material m, Color[] colors, float speed,
ProgressCurve type){
for (int i = 0; i < colors.Length; i++){
yield return StartCoroutine(FadeMaterialColorTo(m, colors[i%2], speed, type));
}
yield return null;
}
IIRC,像yield return somefunction()
如果您有其他嵌套的内部收益率将产生只有一次somefunction()
,当你用做yield return null
在你的体内while
循环。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句