'Unity New Input system click UI elements

My game is a 3D shooter, and the player can shoot if left mouse button is clicked.

The problem is that I have also an UI Menu with buttons to restart the game, but I cannot click those buttons because in my action map click is equal to shoot.

I try to disable the player input and change the current action map to none, so I can press the buttons like the old input system with the Onclick() but it doesn't work.

At the time of displaying a Game Over screen I tried to disable the lock of the cursor.

     PlayerController.sharedInstance.GetComponent<ThirdPersonController>().enabled = false;
     PlayerController.sharedInstance.GetComponent<StarterAssetsInputs>().cursorLocked = false;
     PlayerController.sharedInstance.GetComponent<StarterAssetsInputs>().cursorInputForLook = true;

I think I can start shooting raycast and check what element of the canvas is hit, and by the name of the button perform actions by I don't think this is the best idea.

Could you tell how can I click my UI elements please?

Thank you in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source