Can't call function inside IF statement [solved]

I’m trying to code a jump mechanic (notvthe topic) but whenever i try call any function inside an IF stetement, the parenthesis change color and it doesn’t work

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor.Callbacks;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour

{

    private Vector2 movdir;

    private InputAction move;

    [SerializeField] private Rigidbody2D body;

    [SerializeField] private float speed = 10f;

    [SerializeField] private float jpforce = 100f;

    public PlayerInputs PInput;

    private InputAction jump;

    private bool isjump = false;

    [SerializeField] private int jpt = 100;

    private int jp;

    void Awake(){
        PInput = new PlayerInputs();
    }
    private void OnEnable() {
        move = PInput.Base.Move;
        jump = PInput.Base.Jump;
        jump.Enable();
        jump.started += Jump;
        jump.performed += Jumped; 
        move.Enable();
        }
    private void OnDisable() {
        jump.Disable();
        move.Disable();
    }
    private void Jump(InputAction.CallbackContext context) {
        isjump = true;
        
        Debug.Log("apertou" + isjump);
    }

    private void Jumping(){
        body.AddForce(transform.up * jpforce, ForceMode2D.Impulse);
        jp --;
    }
    private void Jumped(InputAction.CallbackContext context)
    {

        isjump = false;
        Debug.Log("soltou");
    }
    void Start()
    {
      
    }

    private void FixedUpdate(){
        body.velocity = new Vector2(movdir.x*speed, body.velocity.y);
        if (isjump){
            Debug.Log("jumpingg");
        }

        
    }
    void Update()
    {
        movdir = move.ReadValue<Vector2>();
        if(jp == 0){
            isjump = false;
        }
        
    }
}

The variable “isjump” is being set as true, but nothing happens, i even tried to put the if statement on Jumping();

Are you sure that isjump is set to true? Do you see the message in the console?

If it’s not, then take Debug.Log() up to a higher nesting level until you see a message in the console to define where is the issue.

You got bugs.

For one, Jumping() is not called anywhere in the code above (at least that I can see).

For two, lines 78/79 set isjump to false when jp == 0, which of course it will be because you don’t change it.

This means it is… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

1 Like

i forgot i removed the line where i set jp to a number, thanks!