My Button Script isn't working with multitouch?!?!?!?!

function Update () {
    hit = Physics2D.Raycast(camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
        for(var i : int = 0; i < Input.touchCount; i++) {
        var touch : Touch = Input.GetTouch(i);
        if(Input.GetTouch(i).phase == TouchPhase.Began){
           
            if( hit != null &&  hit.collider.gameObject.name == "Right"){
                Right.GetComponent(SpriteRenderer).sprite = afterRight;
                bool = true;
            }

            if( hit != null && hit.collider.gameObject.name == "Left"){
                  Left.GetComponent(SpriteRenderer).sprite = afterLeft;
                  bool2 = true;
            }
        }
        }
           
}

for some reason this code isn’t working with multitouch. Its a code for the arrow buttons to control the character. But I want to be able to touch 2 buttons at a time- for example to touch both the right button and the jump button. But it would only allow me to touch one. Whats wrong with my code?!?! Btw this code is attached to the camera.

Your “hit” variable is defined based on the position of the mouse. For touch applications, Unity simulates the mouse position as the same as the first touch position, but for multitouch applications you’ll need to perform a new raycast for each touch (personally, I don’t like using Input.mousePosition even for single touch applications - it’s undocumented and I’d rather explicitly code using Touch.position).

Can you give me an example how to do that?

Check out the examples (particularly the last one) in the Method Reference. Unity - Scripting API: Input.GetTouch