How ? My code is this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float speed = 2.5f;
private float hI;
private Rigidbody2D rb;
public bool jeNaZemi = true;
private bool vPravo = true;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
hI = Input.GetAxis("Horizontal");
transform.Translate(Vector3.right * hI * speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && jeNaZemi)
{
rb.AddForce(Vector3.up * 30, ForceMode2D.Impulse);
jeNaZemi = false;
}
if(vPravo == false && hI > 0)
{
Pretocit();
} else if(vPravo == true && hI < 0)
{
Pretocit();
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
jeNaZemi = true;
}
void Pretocit()
{
vPravo = !vPravo;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}