is there a way to ignore a click when i press on a button?
hi, i have a code that moves my player when i press the screen using this code if (Input.GetMouseButtonDown (0))
however it still moves the player i when i press a button on the screen which is not how i want it to work. is there a way to fix this?
Comment
i think you can raycast to see if you hit the button and if you did add a boolean like
if(!buttonHit)
{
movePlayer();
}
else if(buttonHit)
{
//do the button stuff
}
Answer by ThaiCat · Jan 11, 2017 at 11:42 AM
I used this as a solution
bool mouseOnUIObject = UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject();
if (!mouseOnUIObject)
{
//do action
}
it does not work properly for me. Thank you. i ended up writing my code again on the button i press so as it duplicates itself and cancels out.