c# - 跳跃动画在第一次跳跃中结束太快
问题描述
void FixedUpdate()
{
moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
anim.SetBool("isWalking", true);
if (facingRight == false && moveInput>0)
{
flip();
}
else if (facingRight == true && moveInput < 0)
{
flip();
}
else if (moveInput == 0)
{
anim.SetBool("isWalking", false);
}
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
}
void Update()
{
if (isGrounded == true)
{
Debug.Log("is grounded");
extraJumps = extraJumpValue;
anim.SetBool("isJumping", false);
}
if (Input.GetKeyDown(KeyCode.Space) && extraJumps + 1.0f > 0)
{
jump();
extraJumps--;
}
}
void flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
void jump()
{
rb.velocity = Vector2.up * jumpForce;
anim.SetBool("isJumping", true);
}
}
我刚开始学习统一,是从 YouTube 上的教程开始的。但是我不明白为什么我的跳跃动画在我第一次跳跃时就结束了。在额外的跳跃中它工作正常。如果您知道如何解决此问题,请帮助我。
解决方案
在您的更新循环中,您调用 Jump 设置
anim.SetBool("isJumping", true);
在您的固定更新循环中,您有
anim.SetBool("isWalking", true);
因此,在下一个“FixedUpdate”调用 Jump 之后,您立即设置 iswalking 的动画布尔值,除非 moveInput 为 0。我看不到您的所有代码或 moveInput 发生的情况,但我可以告诉您这是您的问题所在. 您需要更改此代码的动画:
anim.SetBool("isWalking", true);
if (facingRight == false && moveInput>0)
{
flip();
}
else if (facingRight == true && moveInput < 0)
{
flip();
}
else if (moveInput == 0)
{
anim.SetBool("isWalking", false);
}
推荐阅读
- vb.net - 同时解析不同分区的HTML表格写在listview上
- android - 导航标头不显示来自 Kotlin 中 MainActivity 的文本值
- ios - 无法在 UITableViewCell 中显示
- qt - QLineEdit 输入过滤
- javascript - 处理由另一个函数调用的异步函数时出现问题
- java - 程序类型已存在:com.google.android.gms.common.api.internal.zzd /android studio
- c++ - 使用 std::common_type_t 的 C++ 矩阵类运算符和复数的实现
- c++ - 在 C++ 中使公共数据成员无法访问
- android - 插入该行后,我的应用程序停止响应 myrv.setAdapter(myAdapter);
- javascript - 将 Object 属性值转换为浮点数