So in visual studio line goes
public float enemySpeed = 0.2f;
but in Unity when I change it to lets say enemySpeed = 1 it stays like that even when I stop "Game" and restart Unity even tho its enemySpeed = 0.2f in script.
Changing the value next to the declaration and initialization of the public member won't change in the inspector. Once Unity serialize your public variable, the value is kept until you change it in the inspector.
However, if you look at the component, in the inspector, you will see a little gear on the right. Click on it and click on Reset. The value you have set in code will be set in the inspector. But be careful, all your class'members will be reset too.

You can override the MonoBehaviour's Reset function if you want.
An other workaround would be to set your variable private, let Unity reserialize your component and put the member back to public. (But it may break your code since other scripts may need to reference your class member)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With