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
0
Question by markzareal · Dec 05, 2014 at 07:02 AM · javascripttouchmultitouchtouchcount

touchCount not recognized with multitouch

I have a script that uses touchCount and Raycast and when I played it it does not work with multitouch:

 if(Input.touchCount > 0) {
         hit = Physics2D.Raycast(camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
         
         if(Input.GetTouch(0).phase == TouchPhase.Began){
             
             if( hit != null &&  hit.collider.gameObject.name == "Right"){
                 //Other Stuff
             }
         }
     }

Why wouldn't it work with multitouch?

Comment
Add comment · Show 8
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 Redeemer86 · Dec 05, 2014 at 07:21 AM 0
Share

In line 2... Try using ... Input.GetTouch(0).position ... Or ... Input.GetTouch(0).deltaPosition .. Ins$$anonymous$$d of .. Input.mousePosition... As you require ..

Also probably try writing seperate conditions for input.touchCount == 1 and ... Input.touchCount == 2... Probably single touch taking precedence right after touch detection.

Red

avatar image Redeemer86 · Dec 05, 2014 at 07:32 AM 0
Share

If you are writing seperate conditions .. Of course you would have to remove the condition... Input.touchCount > 0.

avatar image markzareal · Dec 05, 2014 at 07:36 AM 0
Share

but I've also got an Input.GetTouch(0).phase == TouchPhase.Ended @Redeemer86

avatar image Redeemer86 · Dec 05, 2014 at 07:52 AM 0
Share

@markzareal ... Input.mousePosition is not equivalent to a second touch if you are using both input.mouseposition and input.gettouch(0) ... Input.getmousebutton(0) is kind of synonymous in functionality to a single touch (input.gettouch(0))on touch devices .. While input.getmousebutton(1) is synonymous in functionality to a double touch (input.gettouch(0) and input.gettouch(1)) ... It would be better if you distinguished between different conditions. And used input.gettouch(0).position for single touch condition and both input.gettouch(0).position and Input.gettouch(1).position for double touch and so on. Using mouse position and gettouch does not Imply double or multi touch.

Red

avatar image markzareal · Dec 05, 2014 at 07:56 AM 0
Share

Can you give me an example how to use Input.mousePosition? I want mul$$anonymous$$ch because I have arrow buttons on my screen so I want the player be able to hold 2 buttons at the same time

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HarshadK · Dec 05, 2014 at 07:39 AM

If you really want to support multitouch then you need to code for each touch. If each touch performs the same action then you can use a for loop as below:

 if(Input.touchCount > 0) {
     for(int i = 0; i < touchCount; i++) {
           hit = Physics2D.Raycast(camera.ScreenToWorldPoint(Input.GetTouch(i).position), Vector2.zero);
          
          if(Input.GetTouch(i).phase == TouchPhase.Began){
              
              if( hit != null &&  hit.collider.gameObject.name == "Right"){
                  //Other Stuff
              }
          }
      }
 }

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 markzareal · Dec 05, 2014 at 10:01 AM 0
Share

it didn't work

avatar image HarshadK · Dec 05, 2014 at 10:05 AM 0
Share

What is the output? Can you provide details as to what behavior you are getting?

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

26 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

touch input certain screen part 1 Answer

Destroying object by touch on Android? (JS) 1 Answer

Multitouch with two Different Scripts 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