C# Detect Touch without delay

Hey, i’m using this code to check Right and Left clicks:

  	if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began){
			Touch touch = Input.GetTouch(0);
			if (touch.phase == TouchPhase.Began){
				if (touch.position.x > (Screen.width/2)){
					rigidbody2D.AddForce (Vector2.up*300);
					rigidbody2D.AddForce (Vector2.right*150);
					rigidbody2D.velocity = new Vector2(0.0f,0.5f);
					transform.rotation = Quaternion.Euler(0,0,0);
				}
				if (touch.position.x <= (Screen.width/2)){
					rigidbody2D.AddForce (Vector2.up*300);
					rigidbody2D.AddForce (Vector2.right*-150);
					rigidbody2D.velocity = new Vector2(0.0f,0.5f);
					transform.rotation = Quaternion.Euler(0,180,0);
				}
			}
		}

But when it detects a touch it has a delay to check the next touch, in my project I need to remove this delay so that the person can touch the right and quickly after touching the left.

Hi, this script is so baffling. You’ve tested for TouchPhase.Began twice, and repeated multiple lines of code unnecessarily as well.


I don’t know if this works. Feel free to try it.

        if (Input.touchCount > 0 && Input.GetTouch(Input.touchCount - 1).phase == TouchPhase.Began)
        {
            Touch t = Input.GetTouch(Input.touchCount - 1);
            bool leftOrRight = t.position.x > Screen.width / 2;

            rigidbody2D.AddForce(Vector2.up * 300);
            rigidbody2D.AddForce(Vector2.right * leftOrRight ? 150 : -150);
            rigidbody2D.velocity = new Vector2(0.0f, 0.5f);
            transform.rotation = Quaternion.Euler(0, leftOrRight ? 0 : 180, 0);
        }

Hope this helps or at least points you in the right direction. -Greg