im new to unity but i started about a couple weeks ago and now im making my first game which is going to be a 3d platformer but i cant figure out how to fix infinite jumping, could you guys give me some simple beginner friendly solutions?
here is the code in C#
this code is a mix of stuff from tutorials and the internet that i edited that made it more suitable for me
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 2.0f;
public GameObject character;
public float jumpForce;
public Rigidbody rb;
void Update()
{
if (Input.GetKey(“d”))
{
transform.position += Vector3.right * speed * Time.deltaTime;
}
if (Input.GetKey(“a”))
{
transform.position += Vector3.left * speed * Time.deltaTime;
}
if (Input.GetKey(“w”))
{
transform.position += Vector3.forward * speed * Time.deltaTime;
}
if (Input.GetKey(“s”))
{
transform.position += Vector3.back * speed * Time.deltaTime;
}
if (Input.GetButtonDown(“Jump”))
{
rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
}
}
}