- Home /
how to stop UI from affecting player direction on touching .
I am making an android game like zig - zag so when i build and run my game on android and tap a UI it's affecting the balls position ,which it should'nt. While on editing on pc if I run the game the UI is'nt affecting the position of ball(expected result ). Please Help.`
// Do ball rolling things if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject() == false) // works on pc only { if(Input.) rb.velocity = new Vector3(speed, 0, 0); started = true;
gameManager.instance.StartGame();
Destroy(GameObject.FindGameObjectWithTag("Ground"), 6f);
}
Health.instance.gameStart = true;
}`
Any touch at all is considered $$anonymous$$ouseButton(0), and two touches in $$anonymous$$ouseButton(1).
But I would highly recommend using a touchpad or joystick system and some crossplatform input ins$$anonymous$$d.
Actually, touch acting as mouse input can be disabled using Input.simulate$$anonymous$$ouseWithTouches.
By separating mouse and touch inputs into their own schemes, I've never had issues with EventSystem.current.IsPointerOverGameObject() failing to give a proper result.
Thanks for your answer. EventSystem.current.IsPointerOverGameObject() is working fine But! On PC only and when i build and run it on my android device it's not working . As my player(Ball) should only change position when player touches the screen ,not the UI and it's fine in PC but not on my Phone.
Thanks a lot for your answer.I have already completed half of my project using "$$anonymous$$ouseButtonDown" so changing it might create some serious bug issues for me as i am still learning about c# and unity , so i am trying to stick to my code and solve the issues . So is there any way by which I can stop UI elements from feeding Input to my player $$anonymous$$ovements. @RobAnthem