I have tried to make a 2D PlayerMovement
script and my jumping mechanics doesn’t work.
Please let me know what to change.
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float speed;
private Rigidbody2D body;
private void Awake()
{
body = GetComponent<Rigidbody2D>();
}
private void Update()
{
body.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, body.velocity.y);
if (Input.GetKey(KeyCode.Space))
{
body.velocity = new Vector2(body.velocity.x, speed);
}
}
}