Hi guys!
I am creating a Jump & Run game in 2D and I want to disable jumping for a section in the level. I am not sure how I can do it. This is my code for jumping:
void Update()
{
if (Input.GetButtonDown("Jump") && IsGrounded())
{
characterRb.velocity = new Vector2(characterRb.velocity.x, jumpForce);
}
if (Input.GetButtonUp("Jump") && characterRb.velocity.y > 0f)
{
characterRb.velocity = new Vector2(characterRb.velocity.x, characterRb.velocity.y * 0.5f);
}
}
private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
}
I think I would use the OnTriggerEnter2D method for hitting the object and include another boolean in the if statement in the update method but that doesn’t sound very clean tho
I hope someone can help me out
Kind regards