using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movementaxis : MonoBehaviour
{
public float MovementSpeed = 1;
public Rigidbody2D r;
public float JumpForce = 1;
bool facingright;
// Start is called before the first frame update
void Start()
{
r = GetComponent<Rigidbody2D>();
facingright = true;
}
// Update is called once per frame
void Update()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
if (Input.GetButtonDown("Jump") && Mathf.Abs(r.velocity.y) < 0.001f) {
r.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
if (movement<0 && facingright == true)
{
flip();
}
if (movement>0 && facingright == false)
{
flip();
}
void flip()
{
facingright = !facingright;
transform.rotation = Quaternion.Euler(0f, 180f, 0f);
}
}
}
}
I wrote a code, but i dont get how im supposed to flip my sprite, when