private Vector2 direction;
[SerializeField]
private float speed;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
direction.x = Input.GetAxisRaw("Horizontal");
direction.y = Input.GetAxisRaw("Vertical");
if (direction.x < 0 && right)
Flip();
else if (direction.x > 0 && !right)
Flip();
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + direction * speed * Time.fixedDeltaTime);
}
private void Flip()
{
right = !right;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}