using UnityEngine;
public class playerCNTRL : MonoBehaviour
{
public float speed;
public float jumpForce;
private float moveInput;
private Rigidbody2D move;
private bool facingRight = true;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
publuc LayerMask whatIsGround;
private void Start()
{
move = GetComponent();
}
private void FixedUpdate()
{
moveInput = Input.GetAxis("Horizontal");
move.velocity = new Vector2(moveInput * speed, move.velocity.y);
if(facingRight == false && moveInput > 0)
{
Flip();
}
else if(facingRight == true && moveInput < 0)
{
Flip();
}
}
private void Update()
{
isGrounded = Physics2D.OverLapCircle(feetPos.position, checkRadius, whatIsGround);
if(isGrounded == true && Input.GetKeyDown(KeyCode.Space))
{
move.velocity = Vector2.up * jumpForce;
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}
В лауер маск надо слой земли а во всё остальльное сами поймёте. главное в чек радиус 0.3 написать