C# Unity动画参数触发器未重置

C# Unity动画参数触发器未重置,c#,animation,unity3d,parameters,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 () {

嗯,我的印象是,动画触发参数应该在设置后自动重置

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

        }
    }
}
使用UnityEngine;
使用系统集合;
公共类脚本:MonoBehavior{
公共游戏对象go;
public bool mouseDown=false;
Vector2鼠标点=新Vector2();
动画师;
无效开始(){
go=GameObject.Find(“SquareParent”);
anim=GameObject.Find(“Square”).GetComponent();
}
无效更新(){
if(Input.GetMouseButton(0)){
mouseDown=true;
}否则{
mouseDown=false;

anim.ResetTrigger(“触发器”)我认为动画在停止之前再次播放的原因是因为编辑器中Animator窗口中的过渡时间太长。

这个答案太晚了……但其他答案都帮不了我,我在其他任何地方都找不到解决方案。最终,我在一堆tr中偶然发现了它错误和错误

确保攻击是触发器类型,而不是布尔类型。最简单的方法是判断它是否看起来像Animator窗口中的一个框,而不是一个圆

它应该是一个圆

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


您可以尝试以下功能:

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

我认为动画在停止之前再次播放的原因是编辑器中的
Animator
窗口中的过渡长度。我认为动画在停止之前再次播放的原因是编辑器中的
Animator
窗口中的过渡长度。我不知道我有一个完整的答案,但我以前也遇到过类似的问题。@GJTT1太棒了!现在一切又正常运行了,但我真的不知道为什么。我所做的只是删除了重置行,然后我改变了转换,但我真的没有改变它的长度或任何东西。非常奇怪。将此作为一个答案发布,我会给你des值得称赞。我发表评论时有点忙。今晚晚些时候,我会快速查看并尝试更新我的答案。很高兴我能提供帮助。不过,请确保您查看unity中所有关于动画的官方教程。它们非常有用!
SetTrigger
如果它实际上是布尔参数,则会引发异常。..would在控制台中非常明显;)