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
4
Question by FTheCloud · Sep 17, 2011 at 10:53 PM · mobiletouchmultitouch

How does multi-touch work

How does Multi-touch work in unity?

I've tried to avoid it throughout my game but now I've hit a wall that I can't get around without addressing this.

I've looked ALOT online and to be honest I just can't find anything that helps me to much.

Could someone explain it like how it works and how to handle it? Like how would you say something like if two fingers are touching, then do whatever.

Thanks alot

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

Answer by Peter G · Sep 18, 2011 at 03:54 PM

Unity handles multi-touch by giving you the number of touches on the screen during a given frame, and/or gives you an array of all touches during a frame. There are two ways of accessing touches, a good way, and a not as good way.

 //The good way;
 var tapCount = Input.touchCount;
 for ( var i = 0 ; i < tapCount ; i++ ) {
       var touch = Input.GetTouch(i);
       //Do whatever you want with the current touch.
 }

This way is good because it doesn't allocate any new memory on the heap. tapCount and touch are both structures, that means they are stack allocated. If you don't know what that means, stack allocated is usually a good thing. If you need to access multiple touches at one time for something like a pinch-spread motion, you can do that just fine too.

 var tapCount = Input.touchCount;
 if(tapCount > 1) {
      var touch1 = Input.GetTouch(0);
      var touch2 = Input.GetTouch(1);
 }

Then there's the not-as-good way of doing it. It isn't necessarily bad, but it does allocate memory on the stack which isn't good.

  var touches = Input.touches;
  for ( var touch in touches) {
      //Do stuff with this touch
  }

that will let you do pretty much the same stuff, its just not as efficient.

Hopefully that will help you out some.

Comment
Add comment · Show 4 · 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 FTheCloud · Sep 18, 2011 at 08:09 PM 0
Share

this helps alot thanks

avatar image DeveloperDude · Jul 22, 2013 at 05:05 PM 0
Share

Hi FTheCloud, did you solve your problem?

Can you give example of code you use after you get those Input.GetTouch?

Thanks.

avatar image abi-kr01 · Oct 10, 2013 at 11:33 AM 0
Share

thanks you Peter G :)

avatar image Srbhunter · Mar 07, 2014 at 05:49 PM 0
Share

The least I can do is to say THAN$$anonymous$$ YOU!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multi touch not working on iOS (does work on Android) 1 Answer

Multitouch with two Different Scripts 0 Answers

Two or more touchs at same time? 0 Answers

mobile input / OnMouseDown / multi touch (most likely) 0 Answers

Mobile - button press while moving (First Person Controls) 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