touchCount not recognized with multitouch

I have a script that uses touchCount and Raycast and when I played it it does not work with multitouch:

if(Input.touchCount > 0) {
		hit = Physics2D.Raycast(camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
        
        if(Input.GetTouch(0).phase == TouchPhase.Began){
        	
        	if( hit != null &&  hit.collider.gameObject.name == "Right"){
        		//Other Stuff
            }
        }
    }

Why wouldn’t it work with multitouch?

If you really want to support multitouch then you need to code for each touch. If each touch performs the same action then you can use a for loop as below:

if(Input.touchCount > 0) {
    for(int i = 0; i < touchCount; i++) {
          hit = Physics2D.Raycast(camera.ScreenToWorldPoint(Input.GetTouch(i).position), Vector2.zero);
         
         if(Input.GetTouch(i).phase == TouchPhase.Began){
             
             if( hit != null &&  hit.collider.gameObject.name == "Right"){
                 //Other Stuff
             }
         }
     }
}