i mean litreally when i emplemented the code my player is doing pretty well he is running , he is walking , he is jumping too but the only problem is that my player is infinite jumping means whenever I press jump he jumps when i again press jump he again jumps without falling to the ground . i am following blackthordphrod tutorial
and i have attached the code and screenshot of my inspector tab
using System.Data.SqlTypes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playercontroller : MonoBehaviour
{
public float JumpForce;
public float speed;
private float moveinput;
private Rigidbody2D rb;
private bool facingRight = true;
private bool isgrounded;
public Transform groundcheck;
public float checkradius;
public LayerMask whatisground;
private int extrajumps;
public int extrajumpsvalue;
void Start()
{
extrajumps = extrajumpsvalue;
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
isgrounded = Physics2D.OverlapCircle(groundcheck.position,checkradius,whatisground);
moveinput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveinput * speed, rb.velocity.y);
if(facingRight == false && moveinput > 0 ){
Flip();
}else if(facingRight == true && moveinput < 0){
Flip();
}
}
void Update(){
if(isgrounded == true){
extrajumps = extrajumpsvalue;
}
if(Input.GetKeyDown(KeyCode.UpArrow) && extrajumps> 0){
rb.velocity = Vector2.up * JumpForce;
extrajumps--;
}else if(Input.GetKeyDown(KeyCode.UpArrow)&& extrajumps == 0 && isgrounded == true){
rb.velocity = Vector2.up * JumpForce;
}
Debug.Log(isgrounded);
}
void Flip(){
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}