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

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.