I’m trying to check if a player is touching the ground in order to turn on or off the jump script in a 2D platform game. I tried a few things but all of them seem to be failing. This is my recent attempt:
public Collider2D playerjumpcollider;
public Collider2D groundCollider;
void Start()
{
playerjumpcollider = GameObject.FindGameObjectWithTag("Player").GetComponent<Collider2D>();
groundCollider = GameObject.FindGameObjectWithTag("Ground").GetComponent<Collider2D>();
}
void Jump()
{
if (Input.GetButtonDown(“Jump”))
{
if (playerjumpcollider.IsTouching(groundCollider))
{
player.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse);
}
}
}