Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by AndrewBilotti · Feb 23, 2016 at 01:41 AM · c#unity 5mobiletouchtap

Detect how long a tap is held

I am making a mobile game, and I need to figure out how long a tap is held. Can someone please help me?

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 AndrewBilotti · Feb 23, 2016 at 01:43 AM 0
Share

also, if you can give me code to detect how long a tap is held and detect if it is a swipe up, tap, or swipe down, then I will give you 20 reputation.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by rushikesh988 · Feb 23, 2016 at 01:14 PM

@AndrewBilotti You can use something like event Trigger for that with the combination of StopWatch from System.Diagnostics . http://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html

Here is an example how you can detect tap duration.

  1. Add EventTrigger Component on a GameObject where you want to detect the tap.

  2. Add Event Types as Pointer down and Pointer Up.

  3. Refer this to the respective public methods in following script.

    using UnityEngine; using System.Collections; using System.Diagnostics;

      public class TouchSystems : MonoBehaviour {
         
             Stopwatch stopwatch;
             void Start()
             {
                 stopwatch = new Stopwatch();
         
         
             }
             void Update()
             {
             }
         
             public void OnPointerUp()
             {
                 stopwatch.Start();
             }
         
         
             public void OnPointerDown()
             {
                 stopwatch.Stop();
         
                 if (stopwatch.ElapsedMilliseconds > 20 * 1000)
                 {
                     //Do Something 
                 }
                 else
                 {
                     //upto you 
         
                 }
         
                 stopwatch.Reset();
             }
         
         }
     
    
    
    
Comment
Add comment · Show 5 · 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 AndrewBilotti · Feb 23, 2016 at 05:39 PM 0
Share

@rushikeshi988

Wow... your quite the touch expert! just curious, why did you do '20 1000' ins$$anonymous$$d of 20000? This worked very well [no lag on my iPad!], and normal unity games make my iPad lag xD. $$anonymous$$uch better than using time.deltatime. Thanks for $$anonymous$$ching me how to use the stopwatch... now I don't have to use time. and reinventing the wheel. Do you, by any chance, also know how to detect if the tap is a swipe up, a tap, or a hold? If you could help me with that, then my game development would be ahead months :). It is so convenient when a pro gives me such a good answer!

avatar image AndrewBilotti · Feb 23, 2016 at 05:40 PM 0
Share

Would an invisible UI game object work?

avatar image AndrewBilotti · Feb 23, 2016 at 05:42 PM 0
Share

Isn't onpointerdown and onpointerup mixed up?

avatar image AndrewBilotti · Feb 23, 2016 at 05:45 PM 0
Share

So pointer down is touch down for touch, etc?

avatar image AndrewBilotti · Feb 23, 2016 at 06:21 PM 0
Share

Help! I did what you said to do, but it doesn't recognize the onpointerdown and on pointerup!

alt text

screen-shot-2016-02-23-at-101918-am.png (64.7 kB)

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

115 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Network Transport Layer API does not work with iOS to PC???? 0 Answers

Cant get Touch Position.x 0 Answers

Touch screen Input Help 1 Answer

Mobile Optimization question 1 Answer

Multi-touch game can only shoot 1 ball at a time 0 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