I’m new to Unity and C# and I’m trying to create a platformer, I’m creating game controls for running right and left and for jumping, if running works well, then jump only responds to 1 press out of 5 for example. So I can’t “spam” jumps. How to fix it?
Here’s the code
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class Player : MonoBehaviour
{
Rigidbody2D rb;
public float speed = 8;
public float jumpHeight = 13;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
Flip();
}
void FixedUpdate()
{
rb.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, rb.velocity.y);
if (Input.GetKeyDown(KeyCode.Space))
rb.AddForce(transform.up * jumpHeight, ForceMode2D.Impulse);
}
void Flip()
{
if (Input.GetAxis("Horizontal") > 0)
transform.localRotation = Quaternion.Euler(0, 0, 0);
if (Input.GetAxis("Horizontal") < 0)
transform.localRotation = Quaternion.Euler(or
I tried assigning another button to jump, but it doesn’t help
1