Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug What is the equivelant of Input.GetKeyDown for new input system

Discussion in 'Input System' started by harrystansfield1972, Jul 4, 2023.

  1. harrystansfield1972

    harrystansfield1972

    Joined:
    Apr 22, 2023
    Posts:
    1
    I thought i figured out a way with the new input system but it doesn't work as other scripts don't read the key as being performed which is F***ing up my code I just need a way to implement getkeydown with new input system this is the way I have done it (Iam trying to fix The interact button)

    Code (CSharp):
    1.  public void Update()
    2.     {
    3.         if (InteractButton)
    4.         {
    5.            
    6.             InteractButton = !InteractButton;
    7.         }
    8.         if (TestButton)
    9.         {
    10.             TestButton = !TestButton;
    11.         }
    12.     }
    13.     private void OnEnable()
    14.     {
    15.         if(playerControls == null)
    16.         {
    17.             playerControls = new PlayerControls();
    18.  
    19.             playerControls.PlayerMovement.Movement.performed += i => movementInput = i.ReadValue<Vector2>();
    20.             if (CanInteract)
    21.             {
    22.                 playerControls.PlayerActions.X.performed += i => InteractButton = true;
    23.          
    24.             }
    25.          
    26.  
    27.  
    28.             if (CanRun)
    29.             {
    30.                 playerControls.PlayerActions.B.performed += i => RunButton = true;
    31.                 playerControls.PlayerActions.B.canceled += i => RunButton = false;
    32.  
    33.             }
    34.  
    35.             if (CanJump)
    36.             {
    37.                 playerControls.PlayerActions.Jump.performed += i => JumpButton = true;
    38.             }
    39.          
    40.             playerControls.PlayerActions.RT.performed += i => CatchButton = true;
    41.  
    42.  
    43.             if (CanEquip)
    44.             {
    45.                 playerControls.PlayerActions.RB.performed += i =>
    46.                 {
    47.                     if (EquipButton)
    48.                     {
    49.                         EquipButton = false;
    50.                     }
    51.                     else
    52.                     {
    53.                         EquipButton = true;
    54.                     }
    55.                 };
    56.             }
    57.          
    58.  
    59.  
    60.         }
    61.         playerControls.Enable();
    62.     }
     
  2. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65