if (hit.collider != null)
{
Debug.Log(hit.collider.gameObject.name);
if (isGrounded() && hit.collider.gameObject.name != "Player")
{
rigidbody2D.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}
}
Может выского прыгать, а может низко
jumpForce не меняется
Код isGrounded()
private bool isGrounded()
{
float extraHeight = 0.1f;
RaycastHit2D raycastHitGround = Physics2D.Raycast(boxCollider2D.bounds.center, Vector2.down, boxCollider2D.bounds.extents.y + extraHeight);
Color rayColor;
if (raycastHitGround.collider != null)
{
rayColor = Color.green;
}
else
{
rayColor = Color.red;
}
Debug.DrawRay(boxCollider2D.bounds.center, Vector2.down * (boxCollider2D.bounds.extents.y + extraHeight));
return raycastHitGround.collider != null;
}