【问题标题】:Unity animation plays twiceunity动画播放两次
【发布时间】:2015-09-17 15:00:21
【问题描述】:

我创建了一个名为 AnimationController 的类,但我遇到了问题。当我按下space 时,它会触发Animator 中的Jump 动画,但它会播放两次。我不知道为什么要这样做。有什么更好的方法来解决这个问题?

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Animator))]
public class AnimationController : MonoBehaviour {

    Animator animator;
    AnimatorStateInfo baseLayer;

    void Start() {
        animator = GetComponent<Animator>();
        baseLayer = animator.GetCurrentAnimatorStateInfo(0);
    }

    void Update () {
        if(Input.GetButton("Jump") && !baseLayer.IsName("Jump")) {
            animator.SetTrigger("Jump");
        }

    }
}

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    我对 Unity 很陌生,但我怀疑这是因为您使用的是 GetButton 而不是 GetButtonDownGetButtonUp

    来自文档,对于GetButton

    当 buttonName 标识的虚拟按钮被按住时返回 true。

    因此,如果您按住空格键两帧(即使您按下了一次,实际操作所需的时间也比一帧长),那么它将触发两次。如果你按住它的时间超过这个时间,它会一直开火。

    如果您改用 GetButtonDownGetButtonUp,它应该只触发一次,用于印刷机注册的确切帧。

    在用户按下由 buttonName 标识的虚拟按钮的帧期间返回 true。

    【讨论】:

    • 这就是问题所在,我总是忘记哪个是哪个。谢谢!
    • 谢谢!我花了很多时间修复动画:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 2023-02-24
    • 1970-01-01
    • 2016-07-21
    相关资源
    最近更新 更多