Unity 3D Game Engine – Android – Multi Touch – Basics

With this JavaScript code you can check multi touch over an Android device.

1. Create a GUI Text
2. Main Camera, attach the script ‘MultiTouchDetector.js’

MultiTouchDetector.js


#pragma strict

// Rileva il numero di tocchi che avviene contemporaneamente sul dispositivo

var TouchesCounter  : GUIText;  // to display position of finger, Hierarchy DRAG E DROP over var GUI Text in Inspector

function Update () {  
    
	// If there are 1 touches on the device...
    if (Input.touchCount == 1)   
    {
    TouchesCounter.text = "Touches: 1";
	}
    
	
	// If there are 2 touches on the device...
    if (Input.touchCount == 2)  
    {
     TouchesCounter.text = "Touches: 2";
	}
     

	// If there are 3 touches on the device...
    if (Input.touchCount == 3)
    {
    TouchesCounter.text = "Touches: 3";
	}
    
    
    	// If there are 4 touches on the device...
    if (Input.touchCount == 4)  
    {
    TouchesCounter.text = "Touches: 4";
	}
    
    
    	// If there are 5 touches on the device...
    if (Input.touchCount == 5)
    {
    TouchesCounter.text = "Touches: 5";
	}
    
}

Hierarchy> Main Camera> Inspector> MultiTouchDetector.js> DRAG GUI Text over public var TouchesCounter

In this example you can check if over the display you will have 1,2,3,4 or 5 fingers.