Hey I jumped my character in unity but he jumps then he flies too by rapidly space pressing I wrote the following code
(Please help out this beginner!)
this is my code because I was having errors in parsing the upload file
public int movespeed;
public int jumppower;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask whatIsGround;
private bool onGround;
public Rigidbody2D rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
movespeed = 10;
jumppower = 5;
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
rb.velocity = new Vector2(-movespeed, rb.velocity.y);
}
if (Input.GetKey(KeyCode.RightArrow))
{
rb.velocity = new Vector2(movespeed, rb.velocity.y);
}
void FixedUpdate()
{
onGround = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius,
whatIsGround);
}
if (Input.GetKey(KeyCode.Space) && onGround)
{
rb.velocity = new Vector2(rb.velocity.x, jumppower);
}
so then I got outputs for check ground raduis I created a player child game object and named it checked ground then for what is ground I selected the ground layer but it is saying the console is saying the local function FixedUpdate is declared but never used
Everything is working fine except jumping, It’s not jumping anymore