HELP!!!!!!!

I want to control my character’s jump to have him do only one jump at a time so I wrote this code, but it shows error CS0116 on ‘void update()’
Here’s my code-

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class jump : MonoBehaviour
{
private bool canJump;
private Rigidbody2D rb;

// Start is called before the first frame update
void Start()
{
rb = GetComponent();
}

// Update is called once per frame
void FixedUpdate()
{
if (canJump)
{
canJump = false;
rb.AddForce(0, forceConst, 0, ForceMode.Impulse);
}
}
} public void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.Space))
{
canJump = true;
}
}

PLS help as quickly as you can…

try changing fixedUpdate to Update

Use code tags please so it is easier to read. Also, you have FixedUpdate twice. Also also, in your first FixedUpdate you say if(canJump) and then you immediately set it false. put canJump = false after the AddForce part.

This actually doesn’t matter. Once the if-condition is met, the entire block will run no matter when you set the condition to false again.

1 Like