1

我正在使用 C#,目前正在构建第三人称视角游戏。我有一个带有帧动画的 3D 角色模型,所以我必须逐帧剪切动画

问题是我目前有 5 个动画(空闲、跑步、步行、打孔、跳跃),这是我的代码

void Update () {
    if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0){
        //play run animation
    } else {
        if (motion.x != 0 || motion.z != 0){
            motion.x = 0;
            motion.z = 0;
        }
                    //play idle anim
    }

    if (Input.GetKeyDown(KeyCode.Space) && controller.isGrounded){
    //play jump anim
    }

    if (Input.GetKeyDown(KeyCode.P)){
        //play punch anim
    }

    if (!controller.isGrounded){
        //play jump anim
    }

    vertVelo -= gravity * Time.deltaTime;
    motion.y = vertVelo;
    this.controller.Move(motion * Time.deltaTime);
}

当我按 P 使字符打孔时,就会出现问题。似乎正在调用更新函数中的空闲动画,因此打孔动画没有时间播放。

那么,解决方案是什么?是否有任何动画管理技术或者我应该使用延迟?

4

2 回答 2

1

您可以在播放打孔时阻止空闲动画(但这可能不是最佳方法):

bool isPunchPlaying = false;

void Update () {
    //... 
    if (!isPunchPlaying) {
        // Play idle anim
    }
    // ...
    if (Input.GetKeyDown(KeyCode.P)){
        //play punch anim
        isPunchPlaying = true;
        StartCoroutine(WaitThenDoPunch(animation["punch"].length));
    }
    // ...
}

IEnumerator WaitThenDoPunch(float time) {
    yield return new WaitForSeconds(time);
    isPunchPlaying = false;
}
于 2013-02-16T11:57:38.200 回答
0

尝试在 Unity 中搜索动画层并在动画之间进行混合。

您可以在具有较高层号覆盖较低层的层上设置动画循环。

这意味着您可以在第 1 层上有空闲循环,并且它会连续播放。然后说你的跳转循环在第 2 层。当跳转逻辑触发跳转循环时,它会播放一次,然后空闲循环继续。

这个关于 Unity 中“AnimationState”的文档也很有用> 链接 <

于 2013-02-15T13:02:34.267 回答