This is a very simple 2d right & left movement script. I don’t know why it doesn’t work. Is there something I don’t see or the problem isn’t from script?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController2D2 : MonoBehaviour
{
Rigidbody2D rb2d;
// Start is called before the first frame update
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
private void Fixedupdate()
{
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
rb2d.velocity = new Vector2(2, 0);
}
else if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
rb2d.velocity = new Vector2(-2, 0);
}
}
}