问题描述
我正在尝试使用 C# 在我的 Godot 游戏中实现双跳机制,我可以让他跳两次,但我不知道如何将跳数限制为仅 2 次。我尝试使用 jumpCount int 但无济于事。我一直无法找出实现这种机制的最佳方式我对 C# 还很陌生,我知道我的整个播放器脚本几乎都是 if 语句,但这是我能想到的让它工作的最佳方式。>
using Godot;
using System;
public class player : KinematicBody2D
{
const int jumpForce = 125;
const float gravity = 200.0f;
const int moveSpeed = 80;
const float maxFallspeed = 200.0f;
const float acceleration = 10;
float jumpCount = 2;
public Vector2 veLocity = new Vector2(0,-1);
public override void _PhysicsProcess(float delta)
{
var ap = GetNode("AnimationPlayer") as AnimationPlayer;
var sprite = GetNode("playerTex") as Sprite;
veLocity.y += delta * gravity;
veLocity.x = Mathf.Clamp(veLocity.x,-moveSpeed,moveSpeed);
if (veLocity.y > maxFallspeed)
{
veLocity.y = maxFallspeed;
}
if (Input.IsActionpressed("right"))
{
sprite.FlipH = false;
veLocity.x += acceleration;
ap.Play("run");
}
else if (Input.IsActionpressed("left"))
{
sprite.FlipH = true;
veLocity.x -= acceleration;
ap.Play("run");
}
else
{
veLocity.x = 0;
ap.Play("idle");
}
if (Input.IsActionJustpressed("jump") && jumpCount < 2)
{
jumpCount += 1;
veLocity.y = -jumpForce;
}
if (Input.IsActionpressed("jump") && IsOnFloor())
{
jumpCount = 0;
veLocity.y = -jumpForce;
}
if (veLocity.y < 0 && !IsOnFloor())
{
ap.Play("fall");
}
if (veLocity.y > 0 && !IsOnFloor())
{
ap.Play("jump");
}
MoveAndSlide(veLocity,new Vector2(0,-1));
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)