using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] private float speed = 2f; //Скорость
[SerializeField] private float jumpforce = 15f; //Сила Прыжка
private bool isGrounded = false;
private Rigidbody2D rb;
private SpriteRenderer sprite;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
sprite =GetComponentInChildren<SpriteRenderer>();
}
private void FixedUpdate()
{
CheckGround();
}
private void Update()
{
if (Input.GetButton("Horizontal"))
Run();
}
private void Run()
{
Vector3 dir = transform.right * Input.GetButton("Horizontal");
transform.position = Vector3.MoveTowards(transform.position, transform.position + dir, speed * Time.deltaTime);
sprite.flipX = dir.x < 0.0f;
}
private void CheckGround()
{
Collider2D[] collider = Physics2D.OverlapCircleAll(transform.position, 0.3f);
isGrounded = collider.Length > 1;
}
}
Оператор O нельзя применить к типам X и Y
Vector3 dir = transform.right * Input.GetButton("Horizontal");