Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by Sam Bauwens · Nov 19, 2009 at 06:59 AM · guiiphone

Detect when a touch has been captured by the GUI

I'm making a game for the iPhone with GUI buttons. And in Update, I look for touches for another purpose, but I don't wan't to process touches if they are on a GUI element.

The problem is that iPhoneInput.touchCount and iPhoneInput.touches contain all the touch information whether or not it has been processed by GUI, and those variables are actually available in Update and FixedUpdate before GUI gets to do anything with them.

Now I can come up with a hacked solution, no problem (validate the touch data by my GUI function and only use touch data when it has been validated). But I wondered if there is a clean, supported solution.

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by equalsequals · Nov 19, 2009 at 08:38 PM

We originally tried OnGUI() for iPhone, didn't really seem to work well. (probably because of the reasons you defined above)

What we ended up doing was just implementing rectangles for various areas of interest on the screen, and then checking the touches to see if they were within one of those rectangles and at the correct phase. From there we just handled the touch appropriately.

Of course at this point it is no longer immediate-mode because we just had predefined GUITextures in the scene.

Hope that helps.

Comment
Add comment · Show 1 · Share
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 Sam Bauwens · Nov 20, 2009 at 06:42 AM 0
Share

Not using GUI is might indeed be the way to go since they probably won't support address this problem as it would augment latency.

avatar image
0

Answer by Bampf · Nov 20, 2009 at 03:14 AM

In my game the GUI does not normally overlap the gameplay area. The only time it does is when a "modal" dialog box is showing. So before reacting to a click or tap, the gameplay code asks the dialog box manager class if there's a dialog box showing. If there is, the click is ignored.

This works but is a little weak. It requires cooperation between my classes. If I were to write a new class that put up it's own masking visual element, the gameplay code would have to check for that as well.

A more elaborate system might be the following: classes interested in events would register with an event manager class. Before taking any action on a click they would first check to see if they were the "top-most" event handler. If not, they would ignore the click.

This would handle modal dialog boxes, but if you wanted to allow the current event handler to "pass" and let the next handler take an event (a non-modal dialog box for example, when the user clicks outside) then you have a new set of problems to solve.

Comment
Add comment · Share
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
0

Answer by crevelop · Jun 21, 2011 at 01:01 AM

Use layers, create custom layer for your touchable objects and then ignore the rest, or limit your raycasting by creating a layermask, and ignore the objects or areas that you don't want.

Check this out, he uses a layermask ignoring a custom layer named GUI and the ignore Raycast layer, and get touch events from the rest. Apply the same concept, so only when a ray reaches your object(under your custom layer) you will trigger your touch code.

http://www.youtube.com/watch?v=oOfPMKdJdKk

source code is here:

http://www.revelopment.co.uk/tutorials/unitytutorials/73-howtorotateanobjectbytouch

Hope it helps.

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

how to create buttons using iphone look and feel?? 2 Answers

external editor choice?? 1 Answer

IOS App and Aspect Ratio 1 Answer

large slider in the unity 3D 1 Answer

I have problem when i want to using button instead keyboard in iOS 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges