首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >2D动画停留在跳跃动画上

2D动画停留在跳跃动画上
EN

Stack Overflow用户
提问于 2021-01-23 09:34:43
回答 1查看 158关注 0票数 0

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

代码语言:javascript
复制
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;
}

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

EN

回答 1

Stack Overflow用户

发布于 2021-01-23 13:33:06

在此行中,您尚未添加"{}"

代码语言:javascript
复制
if (Input.GetButtonDown("Jump"))
        jump = true;
        animator.SetBool("Jumping", true);

改为这样写:

代码语言:javascript
复制
if (Input.GetButtonDown("Jump")
   {
       jump = true;
       animator.SetBool("Jumping", true);
   }

我看过你用过的Brackey视频..。我的问题是,您是否将PlayerMovement脚本添加到字符控制器的陆地事件中,并选择了您在PlayerMovement脚本中创建的OnLanding()函数?

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65854901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档