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 /
avatar image
0
Question by MPHYS · Jul 11, 2018 at 09:05 AM · unity 5touchtouchscreen

How to use TouchPhase.Ended?

Seems like a really a silly question but shockingly, I'm struggling quite a bit. I've been able to implement TouchPhase.Began and TouchPhase.Moved but I'm not sure how to use TouchPhase.Ended. The following code shows how I'm currently testing for it.

  else if (Input.GetTouch(0).phase == TouchPhase.Ended)
             {
                 Debug.Log("IT HAS ENDED");
             }

This part of my function never gets called and I assume it's because when a touch ends there's no Input. This might be relevant but this code is located in Update().

I do appreciate any and all comments so thank you for reading through and I hope you can help me. Edit: nvm, turns out i was nesting it incorrectly.

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

1 Reply

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

Answer by JavierRuidoRosa · Jul 11, 2018 at 09:21 AM

You can use the phase attribute to register the positions.

 Touch touch = Input.GetTouch(0);
 if (touch.phase == TouchPhase.Began)
 {
     //Register the initial position
 }
 else if (touch.phase == TouchPhase.Moved)
 {
     //Move things using deltaPosition or something else
 }
 else if (touch.phase == TouchPhase.Ended)
 {
     //Register the final position and check if the distance is enough to consider a swipe.
 }

You can also register the initial and final time, so if the time between the start and the end of the touch is too little, you don't consider it a swipe.

I hope this helps!

Comment
Add comment · Show 3 · 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 MPHYS · Jul 11, 2018 at 07:17 PM 0
Share

@JavierRuidoRosa thanks for the solution!! However, I'm having trouble implementing the TouchPhase.Ended bit. I've edited my code, please take a look if it's not too much trouble.

avatar image JavierRuidoRosa MPHYS · Jul 12, 2018 at 07:32 AM 0
Share

Ok, try these things:

  • $$anonymous$$ake sure that conditional is not inside another conditional checking a different phase.

  • Comment all code except that conditional to test it.

  • Save the touch in a variable before checking its phase, like in my example.

Let me know if this works :)

avatar image JavierRuidoRosa JavierRuidoRosa · Jul 12, 2018 at 07:33 AM 0
Share

Oh, I just read the edit. I'm glad you solved your problem! ;D

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

194 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 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

Make object follow my finger (Touch)? 1 Answer

TouchScreenKeyboard textfield move focus 0 Answers

Touches on the far left side not registering due to 3D Touch app switching 0 Answers

define touch area 2 Answers

toucscreen features for mobile in unity can be integrate to a touchscreen monitor? 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