- Home /
How to Ignore Input.MousePosition if button is pressed
I hope I can get some kind of a solution here...
Unity 5.1
Building for Android Platform
I have my player moving based on the input.mouseposition x and y so during a mouse/touch event on the screen the touch/mouse position is getting stored in a xy variable that then gets translated into a direction vector based upon the 2D's character center point...that is all good...
But the issue is when a user is going to touch a button for an in game action that the xy position of the touch get's relayed when the button is pressed and thus throwing the player in a non desired angle as a intended button action is pressed not a "movement press"....
so if the last movement angle is based on 200,100 and then the button is on the edge of the screen so a 500,600 things are not cool.... so the player will be heading at a 200,100 direction and once the button is pressed a immediate change of direction is triggered as the button's xy is way off from the 200,100 position...
So during the button press I need to ignore the input.mouseposition so that the player keeps on moving and the button's event doesn't pass the mouseposition's xy before button press...
I will try to see if I can make some kind of pretrap that once a button is pressed to not change the movements xy private variable...
Hard to describe.. I will try to perhaps make a video to describe the steps.. just trying to throw something out there to get some kind of working solution while I keep coding...
Answer by Dave-Carlile · Jul 22, 2015 at 09:37 PM
Assuming your button is using the new GUI and Canvas and such...
if (!EventSystem.current.IsPointerOverGameObject())
{
// we're not clicking on a UI object, so do your normal movement stuff here
}
Sometimes i cant belive simplest things are the best... thanks very much ;)
Answer by bubzy · Jul 22, 2015 at 09:35 PM
you could put your movement code inside a condition like
//pseudocode
if(mouseButton is not pressed)
{
process mouse coordinate
}
this way it will just ignore the input.mousePosition when its pressed.
hope this helps (if i understood what you wrote properly)