- Home /
How to prevent touch passing through UI ?
Hi guys,
I saw a lot of other questions about this topic but none of them solved my problem. I need to prevent touch passing through UI on mobile. I have some buttons on the main menu and I need to make the game start when touching anywhere on the screen except touching over UI because buttons have their onclick functions and I don't want to start the game and display the settings panel on the same time.
Is there any solution about this ?
Thank you.
I just found out the mistake in my code...I am posting the solution though :P
In the Update() function put this code:
if (Input.touchCount > 0) {
if (Input.GetTouch (0).phase == TouchPhase.Ended) {
if (EventSystem.current.currentSelectedGameObject == null)
{
//here you can put the stuff you want to happen when touching or clicking anywhere except UI...
}
Sorry to bother guys. :)
Your answer
Follow this Question
Related Questions
Advanced Unity: Custom touch input origin 1 Answer
Problem with touch and ui button 1 Answer
Low screen sensitivity on Mobile 3 Answers
Problem with touch and ui button 5 Answers
Make a Triangle instead of a "Rect" 1 Answer