MultiTouch Help(C#)

Hi Guys,

I am developing a app.

I have a script that splits the screen into 2 the left side moves the player and the right side makes the player jump. The problem is that when i move the player and i want to make the player jump at the same time the player doesnt jump. i understand that this is multitouch but i cant seem to find a way to fix this.

i want it so when i move the player and i want to make him jump as he is moving he jumps.

Script

using UnityEngine;
using System.Collections;

public class HalfScreen : MonoBehaviour {
	public float JumpSpeed = 50f;
	public bool grounded = true; 
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if(Input.touchCount > 0 ) 
		{
			var touch = Input.touches[0];
			if (touch.position.x < Screen.width/2)
			{
				transform.position += new Vector3(0.1f,0,0);
			}
			else if (touch.position.x > Screen.width/2)
			{
				if (!grounded && rigidbody2D.velocity.y == 0) {
					grounded = true;
				}
				if ((touch.position.x > Screen.width/2) && grounded == true) {
					rigidbody2D.AddForce (transform.up * JumpSpeed);
					grounded = false;
				}
			}
		}
	}
}

Thank You

You only take into account one touch at a time

var touch = Input.touches[0];

You could use a foreach loop to loop through your multitouches. Something like this should work (untested):

foreach (Touch touch in Input.touches) {

// your if statements for movement and jump

if (touch.position.x < Screen.width/2)
         {
          transform.position += new Vector3(0.1f,0,0);
         }
         else if (touch.position.x > Screen.width/2)
         {
          if (!grounded && rigidbody2D.velocity.y == 0) {
              grounded = true;
          }
          if ((touch.position.x > Screen.width/2) && grounded == true) {
              rigidbody2D.AddForce (transform.up * JumpSpeed);
              grounded = false;
          }
}