【问题标题】:How to get animation to play multiple times in Unity?如何让动画在 Unity 中多次播放?
【发布时间】:2015-06-20 21:37:11
【问题描述】:

我想让一个精灵在每次点击时播放一滴液体落下的动画,但是动画只在我第一次点击时播放,我不知道为什么。

这是精灵上使用的代码:

public class PipetteScript : MonoBehaviour {

public Animator pipetteAnim;
public BoxCollider2D pipetteMove;
public IndicatorScript indicator;

// Use this for initialization
void Start () {
    pipetteAnim.enabled = true;
    pipetteMove.enabled = true;
    indicator.enabled = true;
}

void OnMouseDown () {
    pipetteAnim.Play ("Pipette_dropping");
    Debug.Log ("Anim playing");
    }
}

每次点击精灵时,调试日志甚至会打印出“正在播放动画”。

【问题讨论】:

    标签: c# animation unity3d


    【解决方案1】:

    在更新功能中使用动画并让我更新

    public class PipetteScript : MonoBehaviour {
    public Animator pipetteAnim;
    public BoxCollider2D pipetteMove;
    public IndicatorScript indicator;
    public bool boolval = false;
    
    // Use this for initialization
    void Start () {
        pipetteAnim.enabled = true;
        pipetteMove.enabled = true;
        indicator.enabled = true;
    }
    void update()
    {
     if(boolval == true)
       pipetteAnim.Play ("Pipette_dropping");
     if(boolval == false)
       pipetteAnim.Stop ("Pipette_dropping");
    }
    void OnMouseDown () {
        boolval = True;
        }
    void OnMouseUp () {
        boolval = False;
        }
    

    【讨论】:

    • 我不能将 .Stop 用于 Animator 类型的变量。
    • 然后使用 SetBool like, pipetteAnim.SetBool("Pipette_dropping",false);
    • SetBool 也不起作用,我不得不使用触发器来代替它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    • 2023-02-24
    • 1970-01-01
    相关资源
    最近更新 更多