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
0
Question by darkmwar · Jul 30, 2014 at 08:33 AM · inputbuttontouchevent

Force touch to only work on a new touch - buttons

Hi, I am converting my buttons to touches since 2 GUI buttons doesn't work well when pressed together.

the problem is that when i turn it in to touch, I can't force the touch to cancel right after wards. I want to enforce the code to ONLY work on a new touch. (new touch meaning that the player has to lift their finger off the screen, then touch again --- like a button)

when it is a button, it works fine,

 if (GUI.Button (Rect, "", font)) {                        
 leftClick = true;    
                 }

 if(leftClick){
 //do somehting
 leftClick = false;
 }

This works fine because it only register a "click", the code would not count the continuous touch as a click.

but in touch , if i leave my finger on the "button" then I can't force the "button" to be unpressed (which I need to do). I tried using a tapCount to enforce the touch to be a tap , but that doesn't work.

 foreach (Touch t in Input.touches) {                    
                          
                             if (RightRect.Contains (t.position)&&t.tapCount==1) {
                                         rightClick = true;                                        
                                 }
                         }
                  

 

For example, in game you only want to allow one thing to pass a gate at a time, with gui buttons, the player can leave their finger on the button, but it will only allow one thing to pass. But in touch, if a player leave their finger on there, then it will allow all the things to pass and won't stop after 1 thing. So is there a way to cancel a touch after the user touches the button?

Thanks in advance!

Comment
Add comment · Show 3
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 meat5000 ♦ · Jul 30, 2014 at 08:39 AM 0
Share

https://www.google.co.uk/search?q=unity+touch+tutorial&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&channel=sb&gfe_rd=cr&ei=567YU5OmHojY8gexpYDICg

Brush up on touch. Are you going cross platform or just $$anonymous$$obile/Pad?

avatar image darkmwar · Jul 30, 2014 at 09:18 AM 0
Share

@meat5000 thanks for your comment, ill look in to that right now. It will only be a ios and android app. mobile / tablet

avatar image meat5000 ♦ · Jul 30, 2014 at 09:24 AM 0
Share

Ok, some people fall into the trap of using Clicks in their touch-code. Try to avoid any $$anonymous$$ouse references in your touch handling. If you need to use the mouse you can add in Platform specific directive or use something like Application.isEditor to include your mouse code, for editor usage.

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

detecting touch on gameObject 1 Answer

Button not responsive 1 Answer

GuiTexture touch button problem 0 Answers

How to access other Scripts and Components 1 Answer

Question about user input event handling in Unity game for iOS 2 Answers


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