[英]Unity animation from foreach loop c#
我有一个UI文本,可以在关闭摄像机的脚本中更新,然后使用动画使其在屏幕上滑动。 该脚本使用foreach循环,因为文本更改和动画运行的次数是可变的。 即使调用了4或5个效果,它始终会跳过第三个动画(它将在控制台中打印效果,但不会播放该动画)。
private Animation Anim;
public Text NBtext;
public GameObject NBEffect, Tut, TouchInput;
public IEnumerator NiceBowlingEffects(List<string> Effects, bool FirstFrame)
{
Anim = GetComponent<Animation>();
NBEffect.SetActive(true);
yield return new WaitForSeconds(.2f); //give frame ect a chance to load.
foreach (var Effect in Effects)
{
NBtext.text = Effect;
Print(Effect);
Anim.Play();
yield return new WaitForSeconds(Anim.clip.length);
}
NBEffect.SetActive(false);
if (FirstFrame)
{
Tut.SetActive(true);
}
TouchInput.SetActive(true);
}
尝试在foreach循环中将“ WaitForSeconds ”更改为“ WaitForSecondsRealtime ”,并告诉我是否已修复
希望这可以对某人有所帮助,但最终要使它适用于Nice Bowling,我不得不在更改文本和播放动画之间添加时间延迟。 这是现在在Nice Bowling上运行的代码。
public IEnumerator NiceBowlingEffects(List<string> Effects, bool FirstFrame)
{
Anim = GetComponent<Animation>();
NBEffect.SetActive(true);
yield return new WaitForSecondsRealtime(.1f); //give frame ect a chance to load.
foreach (var Effect in Effects)
{
NBtext.text = Effect;
yield return new WaitForSecondsRealtime(.1f); //text time to change
Anim.Play();
yield return new WaitForSecondsRealtime(Anim.clip.length +.01f);
}
NBEffect.SetActive(false);
if (FirstFrame)
{
Tut.SetActive(true);
Tut.GetComponent<UISprite>().Trigger();
}
TouchInput.SetActive(true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.