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();