Time for action – creating a variable and seeing how it works
Let's see how this actually works in our script. Don't be concerned about the details of how to write this, just make sure your script is the same as the script shown in the next screenshot.
- In the Unity Project panel, double-click on
LearningScript
. - In MonoDevelop, write the lines 6, 11, and 13 from the next screenshot.
- Save the file.
To make this script work, it has to be attached to a GameObject. Currently, in our State Machine project we only have one GameObject, the Main Camera. This will do nicely since this script doesn't affect the Main Camera in any way. The script simply runs by virtue of it being attached to a GameObject.
- Drag
LearningScript
onto the Main Camera. - Select Main Camera so that it appears in the Inspector panel.
- Verify whether
LearningScript
is attached. - Open the Unity Console panel to view the output of the script.
- Click on Play.
The preceding steps are shown in the following screenshot: