public LayerMask groundLayer;
private bool isGrounded;
public Transform feetPosition;
public float groundCheckCircle;
public float jumpTime = 0.35f;
public float jumpTimeCounter;
private bool isJumping;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
input = Input.GetAxisRaw("Horizontal");
if (input < 0)
{
spriteRenderer.flipX = true;
}
else if (input > 0)
{
spriteRenderer.flipX = false;
}
isGrounded = Physics2D.OverlapCircle(feetPosition.position, groundCheckCircle, groundLayer);
if (isGrounded == true && Input.GetButtonDown("Jump"))
{
jumpTimeCounter = jumpTime;
playerRb.velocity = Vector2.up * jumpForce;
}
isJumping = true;
if (Input.GetButton ("Jump") && isJumping == true)
{
if(jumpTimeCounter > 0)
{
playerRb.velocity = Vector2.up * jumpForce;
jumpTimeCounter -= Time.deltaTime;
}
else
{
isJumping = false;
}
}
if (Input.GetButtonUp("Jump"))
{
isJumping = false;
}