• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by G3R1 · Mar 28, 2017 at 05:25 PM · uitouchscreen

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image G3R1 · Mar 26, 2017 at 12:34 PM 1
Share

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. :)

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges