[英]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.