I'm using touch inputs in my game to control the character. I would like to know how to disable my character from jumping again in the air.
if (FingerTouchy.phase == TouchPhase.Ended)
{
charcter.transform.Translate(Vector2.up * speed * Time.deltaTime);
float jumpForce = 250;
charcter.GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce));
}
Update
Im using Collision Detection
void OnCollisionEnter (Collision col)
{
if(col.gameObject.tag == "Ground")
{
grounded = true;
}
}
And checking if charcter is grounded
if(FingerTouchy.phase == TouchPhase.Ended)
{
float jumpForce=250;
if (grounded)
continue;
charcter.transform.Translate(Vector2.up * speed * Time.deltaTime);
charcter.GetComponent<Rigidbody2D>().AddForce(new Vector2(0,jumpForce));
grounded=false;
}
using collision/collision2d doesn't work too.