Making a variable public makes it unchangeable

I’ve been having problems with the variables in my code

When I make the ints rotationLeft and rotationRight public, I cannot change the variables. When I run it in Unity, it just uses the variables rotationLeft and rotationRight were when they weren’t public. When I make them private again, I can change the variables as I please.

public class Rotation_Pivot : MonoBehaviour {
private Rigidbody2D rb2d;

int rotationLeft = 4;
int rotationRight = -2;

void Start()
        {
            rb2d = gameObject.GetComponent<Rigidbody2D>();
        }

    void Update () {
        if (Input.GetKey("right"))
        {
        rb2d.transform.eulerAngles += new Vector3(0, 0, rotationRight);
        }

        if (Input.GetKey("left"))
        {
        rb2d.transform.eulerAngles += new Vector3(0, 0, rotationLeft);
        }

does anyone have any idea what could be going on?

Sounds to meet that you have overwritten the values in the inspector.
if you want to initialize those values in the code, then use the Start() Method.
btw, think about using get,set accessors and use public variables only when needed.

I tried that, now it’s giving me an error that rb2d does not exist in the current context, and the same goes for rotationLeft and rotationRight