Unity动画参数触发器未重置

时间:2016-04-22 14:09:16

标签: c# animation unity3d parameters

我觉得动画触发参数在设置后会自动重置。

using UnityEngine;
using System.Collections;

public class Script : MonoBehaviour {
    public GameObject go;
    public bool mouseDown = false;
    Vector2 mousePoint = new Vector2 ();
    Animator anim;

    void Start () {
        go = GameObject.Find ("SquareParent");
        anim = GameObject.Find("Square").GetComponent<Animator>();
    }


    void Update () {
        if (Input.GetMouseButton (0)) {
            mouseDown = true;
        } else {
            mouseDown = false;
            anim.ResetTrigger ("Trigger");//  <-----------
        }
    }

    void FixedUpdate(){
        mousePoint = new Vector2 (Input.mousePosition.x, Input.mousePosition.y);
        mousePoint = Camera.main.ScreenToWorldPoint(mousePoint);
        go.transform.position = new Vector2 (mousePoint.x,go.transform.position.y);

        if (mouseDown) {
            anim.SetTrigger ("Trigger");

        }
    }
}

但是在整个动画播放之前触发器不会“消耗”自己,之后动画决定再停止播放一次!我可以防止这种情况发生的唯一方法是手动重置触发器(上面指出的线),但现在它只是像布尔一样....所以最重要的是什么?我做错了什么?

3 个答案:

答案 0 :(得分:0)

我认为动画在停止之前再次播放的原因是因为编辑器中Animator窗口中的过渡长度。

答案 1 :(得分:0)

这个答案非常晚......但其他答案都没有帮助我,而我在其他任何地方都找不到合适的解决方案。最终,我偶然发现了一堆反复试验。

确保Attack是Trigger类型,而不是布尔类型。最简单的方法是它是否看起来像Animator窗口中的一个方框而不是一个圆圈。

它应该是一个圆圈。

在下面的图片中,OnGround是一个布尔值(不会重置) 攻击是触发器,将重置

enter image description here

答案 2 :(得分:0)

您可以尝试以下功能:

void AnimTrigger(string triggerName)
 {
     foreach(AnimatorControllerParameter p in animator.parameters)
         if (p.type == AnimatorControllerParameterType.Trigger)
             animator.ResetTrigger(p.name);
     animator.SetTrigger(triggerName);
 }