- Home /
button and touch both active at the same time
Hi everyone
I have a game that moves the player based on input.getTouch.
I also have a button that runs the pause. both work great. the problem is that when i hit the pause button it also calls the movement method. the pause method itself is working fine (all movement is stopping) but the same problem comes up when I unpause it. it will move towards the button since its calling both function of the pause button and the movement method.
how do it set it up so that when i hit the button it doesn't also call the movement method.
*note - the pause button is in the canvas and is controlled with a different script called UIManager
Answer by RohitNutalapati · Dec 06, 2018 at 05:10 PM
Try this in your UI button click method:
// Check if the mouse was clicked over a UI element
if (EventSystem.current.IsPointerOverGameObject())
{
Debug.Log("Clicked on the UI");
}
For Touch:
if(EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
Debug.Log("Touched the UI");
}
is there a similar line for touch controls. It's a mobile app with only touch screen use, no on screen d pad or anything like that. I like that method tho.
@surfuay oh I missed that part.. I updated the answer, pls try that..
Answer by surfuay · Dec 06, 2018 at 05:31 PM
awesome I will try that. does that block it from interacting with the play area or just lets me know I interacted with the UI and then I have to tell it what to do from there.
Your answer
Follow this Question
Related Questions
disable touch when game is paused(Time.timeScale = 0) 1 Answer
Pause code wont work 2 Answers
Time.timeScale doesn't stop void update() from beeing run 1 Answer
Deactivate Swipe Controls on Pause? 0 Answers
Pause menu 1 Answer