Why does not variable change?

Hi! I have code:

        public float randF = -12.0f;  
        bool ToF = true;

        void Update() {
            if (ToF) {
`              ToF = false;

I press “Save” in VS and “Play” in Unity.
Then I change variable: randF = 12;
Press “Save” and result does not change.


Only when I change “public” to “private” or “private” to “public”, result changes.


Because once Unity serializes (saves) the values, changing the initialization value when declaring the variable won’t affect the editor.

You have two options:

  • Change the value in the inspector
  • Change the value when declarign the variable, and then, hit the Reset button inside the menu of the component (top-right corner of the component you will find a little cog)