代码之家  ›  专栏  ›  技术社区  ›  Gaming Gecko

从协同程序播放Unity动画

  •  1
  • Gaming Gecko  · 技术社区  · 7 年前

    正如标题所述,动画未播放。告诉它播放的行在一个协程中,代码在waitforseconds(3f)之前。

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class Play : MonoBehaviour {
    
    public Animator AnimatorRef;
    // Use this for initialization
    void Start () {
        if (AnimatorRef == null)
        {
            AnimatorRef = GetComponent<Animator>();
        }
    
    }
    
    public void PlayGame()
    {
        StartCoroutine(TitlePlay());
        Debug.Log("playing");
    }
    
    IEnumerator TitlePlay()
    {
        Debug.Log("playing1");
        AnimatorRef.SetBool("Enlarge", true);
        yield return new WaitForSeconds(3f);
        Debug.Log("playing2");
    
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
    
    }
    

    它抓住了动画师参考罚款和所有三个评论显示。

    2 回复  |  直到 7 年前
        1
  •  1
  •   Doh09    7 年前

    2注意事项。

    • 第一个-

    你检查了过渡和动画控制器(AnimationController)了吗?

    您可以打开AnimationController,查看布尔值在运行时是否发生变化,如果发生变化,您将知道动画状态之间的某个地方存在转换错误。

    如果您注释掉“LoadScene”部分,那么动画是否正确播放?

    我怀疑动画bool由于某种原因在整个方法运行之前不允许执行其操作,但可能是错误的。

        2
  •  0
  •   Gaming Gecko    7 年前