how can i limit my touch input?

if for example you have a control for mobile where 1 touch counts as 1 jump, how would you limit that touch count to lets say 2 or 3 so after the 2nd or 3rd touch you cant jump anymore until you’ve collided with the Ground in which case the touch count would reset to that specific touch limit

Greetings @darkmon54

Here’s how you would do it if using keyboard. You should be able to modify quite easily for touch input.

using UnityEngine;

public class LimitJump : MonoBehaviour
{
    int jumpCount = 0;
    float jumpForce = 100;
    int maxJumps = 3;
    Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (jumpCount <= maxJumps)
            {
                jumpCount++;
                rb.AddForce(Vector3.up * jumpForce);
            }
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        jumpCount = 0;
    }
}