Game Development Reference
When saving a script in the external editor there is no need to close the
editor. If you keep it open and just click on the Unity window to switch back
it becomes quicker to edit and re-edit script files. You only need to click back
and forth between the Unity and script editor windows to move between
programs. Just remember to save the script file before switching back to
Unity. Unity will automatically reload any script changes you have made.
Step 5. Highlight Cube in the Hierarchy and look at the resize script in
the Inspector at the very bottom. You will notice that the variable has
Remember that variable names cannot have spaces. However, because
the variable name in this case is constructed with capital letters in it, Unity
has made it look like three separate words in the Inspector. objScaleX has
become Obj Scale X . This is only for readability purposes. Your variable is
still called objScaleX in the script.
Step 6. In the Inspector, click on the 0.5 value for Obj Scale X. This will
put the variable into editing mode. Change the value to 0.1 and press
play. The cube will now become very narrow.
When a variable's value is changed in the Inspector, it does not change
in the script. Opening the resize.js in the script editor will review the
objScaleX variable to still have an initial value of 0.5. Any value you type
into the Inspector for a variable will override what you have initialized
the variable within the script. This can quickly become confusing when
you start changing variable values in the script and expect them to affect
the game when nothing seems to happen. If this occurs it is most likely
because the variable is exposed and has a value set in the Inspector.
Step 7. Switch back to the script editor. If you have closed this window,
it can be reopened by double-clicking on resize.js in the Project. Change
the value of objScaleX to 2.0. Don't forget the semicolon after the value.
Step 8. Save the script and switch back to Unity. The Inspector will still
have 0.1 as the value. Playing at this point will give the same results as
before. The Inspector value of 0.1 will override the value in your code.
Step 9. To update the Inspector values to those in the script file, click
on the wheel/cog icon drop down to the very right next to Resize
(Script) and select from the list Reset . Note that the value of objScaleX
has been synchronized with the code in the script file.
Step 10. Play the application to see the cube resized to double its width.