Public Variable always show 0 in Unity editor even I assing it with a number!

Is this a bug or I miss out something?

Sometime the code work and sometime it doesn’t and give the 0 to the Unity editor.

The code is simple. public float sensitive = 10.0f;
I’m trying to make this float public so I can access it from Editor but it always showing 0 for no reason.

And sometime Monodevelop crash for no reason at all. No error message or anything.

Additionally, do you think Visual Studio is better than the Mono IDE?

I personally use VS because MonoDev and my AV don’t get along very well, and VS hasn’t caused me any problems.
As for your float, what are you applying it to?

If you do this

public float f = 0f;

and later change it to

public float f = 10f;

it will retain the original value, because the zero value was sent to the inspector, and it has to obey the inspector value, regardless of the constructor value (otherwise why bother making it public)

You can right-click a component and click reset to make it revert to the scripts’ value

2 Likes

you should do what hpjohn said
You can right-click a component and click reset to make it revert to the scripts’ value.

if you have manually changed this value in the editor then it will ignore the script value. until you reset it.