Weirdness assigning values to health and damage

So I’m uncertain why things are working like this.

If I set the value for health in the declaration (public health = 100f;), it works, and it shows up in the inspector as Health 100.

If I set the value for damage in the declaration, the damage remains at 0 in the inspector, and of course nothing dies. If I set this value inside the GetDamage() function, it works fine. But weirder, if I declare it as private, it works fine.

Anyone have a clue what might be causing this?

The inspector’s values override the code’s declaration’s values. So if damage was already 0 in the inspector, it will override the declaration’s values. This is a “feature” to allow multiple instances of a class, each with a different default starting value chosen in the inspector for each instance.

Privacy & Terms