Search Unity

Resolved The Input only works at times

Discussion in 'Input System' started by JialeHe28, May 29, 2023.

  1. JialeHe28

    JialeHe28

    Joined:
    Sep 16, 2022
    Posts:
    9
    I'm trying to return a boolean that indicates the jump button has been triggered yet it only sometimes returns it
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class InputManager : MonoBehaviour
    7. {
    8.     private BasicMovement _input;
    9.     private InputAction _jump;
    10.     private InputAction _move;
    11.     void Awake()
    12.     {
    13.         _input = new BasicMovement();
    14.        
    15.     }
    16.     private void OnEnable()
    17.     {
    18.         _input.Enable();
    19.  
    20.         _move = _input.Casio.Movement;
    21.         _move.Enable();
    22.        
    23.         _jump = _input.Casio.Jump;
    24.         _jump.Enable();
    25.     }
    26.  
    27.     private void OnDisable()
    28.     {    
    29.         _input.Disable();  
    30.         _move.Disable();
    31.         _jump.Disable();  
    32.     }
    33.  
    34.     public float GetHorizontal ()
    35.     {
    36.        return _move.ReadValue<float>();
    37.     }
    38.  
    39.     public bool GetJump()
    40.     {
    41.         return _jump.triggered;
    42.     }
    43.  
    44.  
    45. }
    46.  
    It literally worked yesterday flawlessly yet it's broken once again with me barely touching anything.
     
  2. JialeHe28

    JialeHe28

    Joined:
    Sep 16, 2022
    Posts:
    9
    Nvm solved it, shouldn't have put the jump on the FixedUpdate