Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 STBarnard · Jul 06, 2015 at 06:14 PM · c#inputtouchscreen

Multi - touch not registering during update.

Hey all,

I have two classes one for character movement and one for character rotation and they work almost identically. I need each class to cache a Touch and recognize when the other class is using a Touch. Here is the code I am trying.

 if (MovementBool)
         {
             if (Input.touchCount > 0)
             {
                 if (Input.touchCount == 1)
                 {
                     MovementTouch = Input.GetTouch (0);
                     if (Pad.Contains (MovementTouch.position))
                     {
                         Point.position = MovementTouch.position;
                     }
                     else 
                     {
                         Point.localPosition = Vector2.zero;
                     }
                 }
                 else if (Input.touchCount > 1)
                 {
                     MovementTouch = Input.GetTouch (1);
                     if (Pad.Contains (MovementTouch.position))
                     {
                         Point.position = MovementTouch.position;
                     }
                     else 
                     {
                         Point.localPosition = Vector2.zero;
                     }
                 }
                 else 
                 {
                     Point.localPosition = Vector2.zero;
                 }
             }
             else if (Input.GetMouseButton (0))
             {
                 if (Pad.Contains (Input.mousePosition))
                 {
                     Point.position = Input.mousePosition;
                 }
             }
             else if (Input.GetMouseButtonUp (0))
             {
                 Point.localPosition = Vector2.zero;
             }
         }

This is all within Update (). Am I mismanaging the touches here?

Thanks

Comment
Add comment · Show 6
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 Owen-Reynolds · Jul 06, 2015 at 07:57 PM 0
Share

The idea here looks wrong. If there are two touches, it looks like the both use the second, and no one uses the first?

Is it possible to have the only touch be movement OR be rotation? (ex: they can tap the joystick icon is steer w/o moving?) How do you keep track of this?

The touch order is fixed (touch#0 is always rotation) then just say: if touch 0 exists, rotate with it. If touch 1 exists, move with it.

Also, the correct way is to look up the internal touch number. If you have a left and right touch, one frame the left touch may be #0, and next frame it can be #1. But, in practice, this only happens when someone has two touches and lets go of the first (touch 1 is now touch 0, but keeps the same internal touch number.)

avatar image tanoshimi · Jul 06, 2015 at 08:04 PM 0
Share

Your logic is wrong. Specifically:

 if (Input.touchCount == 1)
 {
   $$anonymous$$ovementTouch = Input.GetTouch (0);
   ...
 }
 else if (Input.touchCount > 1)
 {
   $$anonymous$$ovementTouch = Input.GetTouch (1);
   ...

in English, "If there's one touch on the screen, use the first touch. Else, if there's more than one touch, use the second touch."...?

avatar image STBarnard · Jul 06, 2015 at 08:35 PM 0
Share

@Tanoshimi That was the intent.

avatar image STBarnard · Jul 06, 2015 at 08:37 PM 0
Share

So does the touch count start at index 0?

avatar image STBarnard · Jul 06, 2015 at 08:39 PM 0
Share

@ Owen, I see, so how do I get the internal touch ID? Is that the fingerID value?

Show more comments

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

C# Touch Script - Fix GameObject touch. 0 Answers

Multiple Cars not working 1 Answer

When i press a button on the game scene its starts the game, how i can solve it ? 0 Answers

Distribute terrain in zones 3 Answers

Can I use OnMouseDown for touch input? C# Nexus 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