Multi touch for character movement on android[solved]

Ok guys , I have been trying to solve this problem for quite some time now. This version of the code is just for testing , I know it will only work if i follow the pattern my code describes. I have tried with a for loop and GetTouch(i) and when it didn’t work I thought to try it like this, and the same problem persists. The problem i’m having is that when I am moving with my character, and then i tap to rotate him, it seems that he isn’t moving that much (or not at all). I have 3 GUITextures , one for moving the character in the forward direction, and 2 for turning left or right. Currently I am testing with only the move and turn left buttons. Here is the snippet:

EDIT: New code for handling touch

// Loop through all the touches on screen if there are any
	if(Input.touchCount > 0){
		for(int i=0;i<Input.touchCount;i++){

			Touch t = Input.GetTouch(i);
			// Check to see if touch is on move_forward button
			if(move_forward.HitTest(t.position) && t.phase != TouchPhase.Ended && t.phase != TouchPhase.Canceled){
				doMove=true;
			}
			// Check to see if touch is on rotate left button
			if(turn_left.HitTest(t.position) && t.phase != TouchPhase.Ended && t.phase != TouchPhase.Canceled){
				doTurnLeft=true;
			}
			// Check to see if touch is on rotate right button
			if(turn_right.HitTest(t.position) && t.phase != TouchPhase.Ended && t.phase != TouchPhase.Canceled){
				doTurnRight=true;
			}
		}
	}

New code for handling movement:

if (doMove == true && (doTurnLeft == true || doTurnRight == true) )  {
			// Translate to new position
			Vector3 position = transform.position;
			position+=transform.forward*move_speed;
			transform.position=position;

			// Rotate
			if(doTurnRight == true)
				transform.Rotate(transform.up,rotation_speed);
			else
				transform.Rotate(transform.up,rotation_speed*-1.0f);

			// Play walk animation
			animation.Play("walk");
		}
		if (doMove == true && doTurnLeft == false && doTurnRight == false) {
			// Translate to new position
			Vector3 position = transform.position;
			position+=transform.forward*move_speed;
			transform.position=position;;
		
			// Play walk animation
			animation.Play ("walk");
		}
		if (doMove == false && (doTurnLeft == true || doTurnRight == true) ) {
			// Rotate
			if(doTurnRight == true)
				transform.Rotate(Vector3.up*rotation_speed);
			else
				transform.Rotate(Vector3.up*rotation_speed*-1.0f);

			// Play idle animation
			animation.Play ("idle");
		}
		if (doMove == false && doTurnLeft == false && doTurnRight == false) {
			//Play idle animation
			animation.Play("idle");
		}

At the start of the Update function I reset the values for doMove,etc to false, that’s why I’m only making them true with my conditions.

LE: So the multi touch seems to work but when i have two touches on screen (one touch on move and one touch simply anywhere else , not on any other button) my character’s speed slows down ,and I can’t figure out what the problem is.

LE2: Notice how in the above code the character transformations occur outside the for loop. If i move them inside the foor loop then the problem disappears. Why is that ?

New code 2(working) :

/ Loop through all the touches on screen if there are any
        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; i++)
            {

                Touch t = Input.GetTouch(i);
                switch (t.phase)
                {
                    case TouchPhase.Began:
                        if (move_forward.HitTest(t.position))
                        {
                            moveFingerID = t.fingerId;
                            doMove = true;
                        }
                        else if (turn_left.HitTest(t.position))
                        {
                            turnLFingerID = t.fingerId;
                            doTurnLeft = true;
                        }
                        else if (turn_right.HitTest(t.position))
                        {
                            turnRFingerID = t.fingerId;
                            doTurnRight = true;
                        }
                        break;
                    case TouchPhase.Stationary:
                        if (doMove && moveFingerID == t.fingerId)
                        {
                            Vector3 position = transform.position;
                            position += transform.forward * move_speed * 1.0f * 1.0f;
                            transform.position = position;

                           
                        }
                       
                        if (doTurnLeft && turnLFingerID == t.fingerId)
                        {
                            transform.Rotate(Vector3.up * rotation_speed * -1.0f * 1.0f);
                        }
                        if (doTurnRight && turnRFingerID == t.fingerId)
                        {
                            transform.Rotate(Vector3.up * rotation_speed * 1.0f);
                        }
                        break;
                    case TouchPhase.Ended:
                        if (moveFingerID == t.fingerId)
                        {
                            moveFingerID = -1;
                            doMove = false;

                        }
                        else if (turnLFingerID == t.fingerId)
                        {
                            turnLFingerID = -1;
                            doTurnLeft = false;
                        }
                        else if (turnRFingerID == t.fingerId)
                        {
                            turnRFingerID = -1;
                            doTurnRight = false;
                        }
                        break;
                    default: break;

                }
            }
            if(doMove)
                animation.Play("walk");
            else
                animation.Play("idle");
        }
        else
            animation.Play("idle");

Multi-touch is complicated. You cannot depend on the ‘GetTouch()’ index remaining the same from call to call. Looking at your code you may be able to just test all fingers against both GUITextures. But if you need to track individual fingers, then you need to do it by Touch.fingerId, not by index. But to start with, put in a foreach() loop and test all touches against the two GUITextures, setting ‘doTurnLeft’ and ‘doMove’. Then process the ‘doMove’ and ‘doTurnLeft’ after the loop.