【问题标题】:2D Animation stuck on jumping animation2D 动画卡在跳跃动画上
【发布时间】:2021-04-27 11:53:23
【问题描述】:

我正在观看一段关于如何制作 2D 动画的旧 brackeys 视频,我相信我已经正确地遵循了教程中的所有内容。一切都很顺利,直到我开始跳跃动画。在着陆功能期间跳跃动画不会停止。视频在这里https://www.youtube.com/watch?v=hkaysu1Z-N8&feature=emb_logo,我的代码是这样的:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public CharacterController2D controller;
public float runSpeed = 80f;
float horiztalMove = 0f;
bool jump = false;
public Animator animator;
// Start is called before the first frame update
// Update is called once per frame
void Update()
{

    horiztalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

    animator.SetFloat("Speed", Mathf.Abs(horiztalMove));

    if (Input.GetButtonDown("Jump"))
        jump = true;
        animator.SetBool("Jumping", true);
}
 public void OnLanding ()
{
    animator.SetBool("Jumping", false);   
}

void FixedUpdate()
{        //move our character
    controller.Move(horiztalMove * Time.fixedDeltaTime, false, jump);
    jump = false;
}

} 如果您希望我发送任何其他代码或屏幕截图,我会发送。

【问题讨论】:

    标签: c# unity3d animation 2d


    【解决方案1】:

    在这一行中,您没有添加“{}”

    if (Input.GetButtonDown("Jump"))
            jump = true;
            animator.SetBool("Jumping", true);
    

    改为这样写:

    if (Input.GetButtonDown("Jump")
       {
           jump = true;
           animator.SetBool("Jumping", true);
       }
    

    我看过你用过的 Brackeys 视频... 我的问题是,您是否将 PlayerMovement 脚本添加到 CharacterControllerOn Land Event 并选择了 OnLanding()您在 PlayerMovement 脚本中创建的 em> 函数?

    尝试检查您是否已添加 OnLanding() 并修复我指出的行中的 {}。 希望我能对你有所帮助。

    【讨论】:

    • 是的,我确实选择了登陆()功能,非常感谢您的帮助。作为一个新手,当谈到统一和 c# 时,这些东西真的很重要
    • 同样在添加这些括号后,我仍然需要点击两次空格才能播放动画。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    相关资源
    最近更新 更多