Do I have to change the value of a pubilic variable in the script even if I have already changed the value in the inspector variable?

I have attached a script to a game object in order to move it. A public variable of type Vector2 is defined to set the speed and values 50 and 0 are given. Now I have a field to set the speed in the inspector. If I change the value from the inspector instead of editing the script, Do I have to change the value in the script when I am going to build the project?

Thank you

No, You don’t need to change it in your script. Unity3d prefer the value given in inspector.

The values set in the inspector will always prevail to the directly defined in your script. That means, that if you do:

public Vector2 myVec = new Vector2 (50f, 0f);

That value will be overridden by the one found at inspector (that’s because of Unity’s internal deserialization). However, if you set that value on the proper Unity callback e.g. Awake, Start, OnEnable… the values found on those methods will be the final values to be used. AFAIK Unity deserialization occurs between script’s constructor and OnEnable callback.

As per the KellyThomas comment above, the value in your script should be the “normal” value for that type of object. If you will only ever make one (like all bullets in the game are identical,) it won’t matter.

Say you will be making lots of monsters, and 8 is a good walk speed. Use 8 in the script. Whenever you make a new type of monster, it starts with 8 in the Inspector. Suppose you want a slower monster – you can easily see the 8 it starts with, and know that 4 is good for a “slow” monster.

If there is no normal value, like for monster hit points, can use something stupid in the script like -999, 1 or 99999. That way, when you make a new monster and test it, you’ll see right away that you forgot to enter the hitpoints.