2

I have added a C# Script to the Main Camera. I defined a variable MyNumber like below -

public int MyNumber = 9;

My problem is when I change the value of the variable; inside the Unity Editor it remains the same. For example if I change the value from 9 to 19 in the C# script file using Monodevelop, the Unity Editor continues to show My Number = 9 instead of 19; unless I reset the script file.

Please check the screenshot: Variable not syncing properly

Ifrit
  • 6,791
  • 8
  • 50
  • 79
Simon Gomes
  • 383
  • 1
  • 5
  • 18
  • you *can not* use Capitals for variables names. you must change it to `int myNumber` – Fattie Mar 06 '16 at 14:00
  • Possible duplicate of [Unable to change array size in Inspector variable in Unity?](http://stackoverflow.com/questions/35165995/unable-to-change-array-size-in-inspector-variable-in-unity) – Fattie Mar 06 '16 at 14:01

1 Answers1

5

This is normal behavior. There's no way for the Unity Editor to know if the old value of 9 was purposely changed in the editor from the default found within your C# script. So it plays it safe and assumes it was modified.

It's important to remember that the script initialized value represents a default value. It does not always guarantee the starting value. Case in point, it's updated in the editor.

Ifrit
  • 6,791
  • 8
  • 50
  • 79