How to implement multi touch in android 2d game?


I want to implement multi touch in android 2d game …
I have 2 groups of buttons like joystick and i have to hit a button from each group …

I control detecting touch from game controller script not from script attached to every button.

This is my work >>

void Update ()

	if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
		RaycastHit2D hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint((Input.GetTouch (0).position)),;
		if(hit.collider != null)
			Debug.Log ("Touched it");

Please help me i did many tries in vain for about one week and i can’t find the solution yet …

this image maybe shows you the idea i want …

Add two blank GUI Textures, half screen each.
On touch check which texture is tapped + button that’s hit.

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:

//one is
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.

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

It isn’t necessarily bad, but it does allocate memory on the stack which isn’t good.
Modern mobile devices have screen that can receive accurate multitouch inputs from the user for more information visit link Multi Touch Input

Do something like this in your code and handle different touches

 // Update is called once per frame
    void Update () {

        // Check to see if the screen is being touched
        if (Input.touchCount > 0)
            // Get the touch info
            Touch t = Input.GetTouch(0);

            // Did the touch action just begin?
            if (t.phase == TouchPhase.Began)
                   //Do your stuff here

Why couldn’t you use the UI events? If you want to do it like you describe you could use the touch array to capture the touches and do something with them after.

     Touch myTouch = Input.GetTouch(0);

        Touch[] myTouches = Input.touches;
        for(int i = 0; i < Input.touchCount; i++)
            //Do something with the touches

Hey guys,
My problem is how can i find the button and detect if it is touched.
I did touches and picked them nicely but how to check if this touch position is touching the button.