Unity 2D Платформер

 

public float speed;
public float jumpForce;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;  // Layer для індикації землі
float moveInput;
Rigidbody2D rb;
bool facingRight = true;
bool isGrounded;

private void Start()
{
  rb = GetComponent<Rigidbody2D>();
}

private void FixedUpdate()
{
  moveInput = Input.GetAxis("Horizontal");
  rb.velocity = new Vector2(moveInput * speed, rb.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))
  {
    rb.velocity = Vector2.up * jumpForce;
  }
}

void Flip()
{
  facingRight = !facingRight;
  Vector3 Scaler = transform.localScale;
  Scaler.x *= -1;
  transform.localScale = Scaler;
}