我正在看一个关于如何制作2d动画的老视频,我相信我已经正确地遵循了教程中的所有内容。在我开始跳跃动画之前,一切都很顺利。在着陆功能期间,跳跃动画不会停止。视频在这里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;
}}如果您希望我发送任何其他代码或屏幕截图,我会发送的。
发布于 2021-01-23 13:33:06
在此行中,您尚未添加"{}"。
if (Input.GetButtonDown("Jump"))
jump = true;
animator.SetBool("Jumping", true);改为这样写:
if (Input.GetButtonDown("Jump")
{
jump = true;
animator.SetBool("Jumping", true);
}我看过你用过的Brackey视频..。我的问题是,您是否将PlayerMovement脚本添加到字符控制器的陆地事件中,并选择了您在PlayerMovement脚本中创建的OnLanding()函数?
尝试检查您是否添加了OnLanding(),并在我所指出的行中修复了{}。希望我能对你有所帮助。<3
https://stackoverflow.com/questions/65854901
复制相似问题