foreach循环C#的Unity动画



我有一个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);
}

尝试更改" waitforseconds "到" waitforsecondsrealtime "中的foreach循环中,并告诉我它是否修复了

希望这对某人有所帮助,但最终使它为不错的保龄球工作,我不得不在更改文字和播放动画之间添加时间延迟。这是现在在不错的保龄球上运行的代码。

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);
}

最新更新