上期我们实现了人物的左右移动和人物的正常翻转(算是正常吧)。这期我们看看如何让人物能够跳跃。本期用到的代码先放下面:
public class Player_control : MonoBehaviour
{
public PlayerInputControl inputControl;
public Vector2 inputDirection;//public变量表示一个公开的方法,它代表我在Unity窗口中可以查看得到。
private Rigidbody2D rb;
private SpriteRenderer rbSprite;
[Header("基本参数")]
public float speed;
public float jumpForce;
private void Awake()
{
rb= GetComponent<Rigidbody2D>();
inputControl = new PlayerInputControl();
inputControl.GamePlayer.Jump.started += Jump;
rbSprite = GetComponent<SpriteRenderer>();
}
private void OnEnable()
{
inputControl.Enable();
}
private void OnDisable()
{
inputControl.Disable();
}
private void Upd