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
1
Question by pretender · Dec 25, 2011 at 05:29 PM · androidinputmultitouch

multitouch problem

hi guys, i am banging my head with this for a while i could really use some help...i think it is trivial for experienced ones

here is what i am trying to do.

i have two buttons and for each of those two buttons i have three states

 enum buttonState{NOT_ACTIVE,AIM,FIRE}

so both buttons should be able to aim and fire. if left button was touched first then it will have aim state and second button if touched will fire. if first button to be touched is right then right will aim and left will fire if touched. if none buttons are touched then both buttons will have not_active state.

i managed to get aim with left and fire for right but it is hard coded, i can not manage to figure out how to generalize the part where touchCount==2 to figure out what is Input.GetTouch(0) and what is Input.GetTouch(1). i guess i will have to track fingerID but i do not know how to implement it

here is the code for case of two touches

 //two touches
 if(Input.touchCount>1){
     if(LeftButton.GetState()==ButtonState.AIM){           
        if(RightButton.GetInputRect().Contains(Vector2(Input.GetTouch(0).position.x,Screen.height-Input.GetTouch(0).position.y))){
            RightButton.SetButtonState(ButtonState.FIRE);
        }
     }
     if(RightButton.GetButtonState()==ButtonState.AIM){
         if(LefButton.GetInputRect().Contains(Vector2(Input.GetTouch(1).position.x,Screen.height-Input.GetTouch(1).position.y))){
            LeftButton.SetButtonState(ButtonState.FIRE);
        }
      }
 }


any help is appreciated!

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
4
Best Answer

Answer by Wumpee-2 · Jan 01, 2012 at 04:33 PM

I'm not sure if you'd need to track touches or finger id. You could probably get away with something like the following:

 if (Input.touchCount > 1)
 {
     for (int i = 0; i < Input.touchCount; ++i)
     {
         if (LeftButton.GetState() == ButtonState.AIM)
         {
             if (RightButton.GetInputRect().Contains(Vector2(Input.GetTouch(i).position.x, Screen.height - Input.GetTouch(i).position.y)))
             {
                 RightButton.SetButtonState(ButtonState.FIRE);
             }
         }
         else if(RightButton.GetButtonState() == ButtonState.AIM)
         {
             if (LeftButton.GetInputRect().Contains(Vector2(Input.GetTouch(i).position.x, Screen.height - Input.GetTouch(i).position.y)))
             {
                 LeftButton.SetButtonState(ButtonState.FIRE);
             }
         }
     }
 }
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 hirenkacha · May 09, 2012 at 05:09 AM 0
Share

but if you are using Touchphases in if condition this will check for all the touches.. which is not needed.. it will require fingerID to resolve the issue.

avatar image hirenkacha · May 09, 2012 at 05:17 AM 0
Share

how to use fingerid in this code???? can u help?????

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I detect the number of touches an Android device is capable of? 0 Answers

¿Unity messing up fingerIDs? [Android] 1 Answer

four simultaneous touch inputs in android 2 Answers

multi-touch woe, index out of bounds? 1 Answer

How to get sensor(e.g. accelerometer) input from external device(phone and similar) to PC Unity editor? 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