my movement with the following script does not work ):
Edit: I restarted unity and now it works for some reason…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 5f;
private float moveinput;
private Rigidbody2D rb;
private bool RechtsSchauen = true;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
moveinput = Input.GetAxis("Horizontal");
Debug.Log(moveinput);
rb.velocity = new Vector2(moveinput * speed, rb.velocity.y);
if (RechtsSchauen == false && moveinput > 0)
{
Flip();
}
else if (RechtsSchauen == true && moveinput < 0)
{
Flip();
}
}
void Flip()
{
RechtsSchauen = !RechtsSchauen;
Vector3 scaler = transform.localScale;
scaler.x *= -1;
transform.localScale = scaler;
}
}