using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 5f;
public float jumpForce = 8f;
public Transform groundCheck;
public float checkRadius = 0.2f;
public LayerMask groundLayer;
private Rigidbody2D rb;
private bool isGrounded;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
// Движение
float move = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(move * speed, rb.velocity.y);
// Проверка пола
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, groundLayer);
// Прыжок
if (Input.GetButtonDown("Jump") && isGrounded)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
}
}