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 salamander555 · Apr 02, 2017 at 01:47 PM · androidtouchtouchesexistsindexof

How can I check if a certain Touch exists?

I can't find a way to check if a certain touch exist script below "foreach (Touch touch in Input.touches) {

                 if (some requierments)
                 {
                     follow = true;
                     followTouch = touch;
                 }
              }"

so my code just make an object follow my touch(I have stored the Touch in a variable 'touch') and once the touch doesn't exists anymore I want it to go back to his native position(this is the parent's position 'transform.parent.transform.position') Things I have tried 1)

 if (Input.touchCount < 1)
 {
 //doesn't work because you often have multiple touches
 }

2)

 if (touch != null)
 
 // but i can't compare a touch value and 'null'

3) there neither is a touch.exist to use

Questions so what's a way to check if a touch is 'alive' or is there maybe a way to find the index of a touch (while the touch is stored in a variable)

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

2 Replies

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

Answer by salamander555 · Apr 03, 2017 at 07:23 AM

Going to answer my own question here just use this if ('TouchVariable'.phase == TouchPhase.Ended) { }

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 gameplay4all · Apr 03, 2017 at 07:31 AM 0
Share

Oh so you wanted the "some requirement" filled in, now I understand your question.

avatar image
0

Answer by gameplay4all · Apr 02, 2017 at 03:47 PM

Not really sure if I understand your question, but instead of saving the touch; save the index! So then you can do things like,

 if(Input.touchCount > followTouch){
 //Do stuff here with Input.GetTouch(followTouch)
 }
 else{
 //The finger is let go.
 follow = false;
 followTouch = -1;
 }

So followTouch is now an int :)

Hope this gets you further!

-Gameplay4all

EDIT:

So you have this piece of code:

 foreach (Touch touch in Input.touches) {
   if (some requierments)
   {
     follow = true;
     followTouch = touch;
   }
 }

Change it to:

 for (int i = 0; i < Input.touchCount; i++) {
   if (some requierments with Input.GetTouch(i) )
   {
     followTouch = i;
   }
 }

Now you can use the code I mentioned in my original answer :)

And where you have followTouch declared, change it to an int.

Comment
Add comment · Show 2 · 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 salamander555 · Apr 02, 2017 at 04:14 PM 0
Share

Can you explain in word what you put here bc i don't really get what you are doing

avatar image gameplay4all salamander555 · Apr 02, 2017 at 04:29 PM 0
Share

See my edited answer, if you want help with objects tracking Touches: there are plenty of answers/tutorials for that already. Like this.

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

138 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

Related Questions

I can't use more that two buttons at the time. How do I change that? 0 Answers

GameObject dropping and laging while dragging on Android 2 Answers

Detect Android device touch points amount. 0 Answers

Unusual multitouch behavior (Android) 3 Answers

Need Android Help - How do I click and mouseover a 3d object? 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