Jump resets when in air (C#)

I have a script for my player it worked fine, but i found a glitch which is when the player jumps and they are in the air, if they move and jump they keep jumping.

CODE

using UnityEngine;
using System.Collections;

public class HalfScreen1 : MonoBehaviour {
public float playerSpeed;
public float jump;

//Grounded Vars
bool grounded = true;
void Start () {
	
}

// Update is called once per frame
void Update () {

	foreach (Touch touch in Input.touches) {
		
		// your if statements for movement and jump
		
		if (touch.position.x < Screen.width/2)
		{
			transform.Translate(Vector2.right * playerSpeed * Time.deltaTime);
		}
		else if (touch.position.x > Screen.width/2)
		{
			if(grounded)
			{
				GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, jump);
			}
		}
	}
}

In the first line of Update check with Physics.Raycast if the player is grounded or not, elsely grounded will stay true all the time.

Your issue is that you never set “grounded” to false. So when the play jumps and is in the air, the game still thinks that they are grounded, and if the player taps the screen to jump again, the game will think that it is valid to do so.

What you want to do is

GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, jump);
grounded = false;

then, you must set grounded to true again when the player touches the ground.