l am using Unity UI Toolkit and New Input System.
My game logic is when l press left mouse button, object should start move. Also there is a power-up button in view, l created with UI Toolkit and wrote script like this.
void Start()
{
VisualElement menuRoot = GetComponent<UIDocument>().rootVisualElement;
Button firstPowerUp = menuRoot.Q<Button>("first_power_up");
firstPowerUp.clicked += () => {
Perform();
};
}
void Perform()
{
Debug.Log("Clicked on power-up!");
}
Button works, okay. But Input Actions also works. So, my button and object movement works together. How can l solve this problem or seperate input systems?
l tried so many ways:
- Disabling InputAction when UI button clicked
- Tried to use EventSystem with EventSystem.current.IsPointerOverGameObject()
- Researched about UI maskers but l think solution should be simpler
- Tried to change some properties in UI Builder and so on.
Looks like that you don't need to move object every time when you click (in case of button click for example), so you shouldn't bind mouse click to object movement directly.
1, Create script, that will get signal when you perform mouse click instead of old movement script.
2, Add this check to the new script: