Search Unity

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

Question Input System Cannot Dectect My Mouse Click

Discussion in 'Input System' started by Akiii299, Nov 22, 2023.

  1. Akiii299

    Akiii299

    Joined:
    Sep 5, 2022
    Posts:
    1
    upload_2023-11-22_1-11-35.png
    I am having a problem with the input system. As the screenshot shows below, I have an action called WeaponMainFunc which is bonded to the left mouse button click. However, in the script below, the left button click is never detected. In other words, the bool variable IsWeaponMainFuncPressedThisFrame is never true. Did I do something wrong here? Does anybody know how to fix this issue?

    Code (CSharp):
    1. public class PlayerInputHandler : MonoBehaviour
    2. {
    3.     public static PlayerInput PlayerInput;
    4.     private InputAction _weaponMainFuncAction;
    5.     public static bool IsWeaponMainFuncPressedThisFrame { get; private set; }
    6.  
    7.     private void Awake()
    8.         {
    9.             PlayerInput = GetComponent<PlayerInput>();
    10.             _weaponMainFuncAction = PlayerInput.actions["WeaponMainFunc"];
    11.         }
    12.  
    13.    private void Update()
    14.     {
    15.         IsWeaponMainFuncPressedThisFrame = _weaponMainFuncAction.WasPressedThisFrame();
    16.     }
    17.  
    18. }