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.

  1. In the Unity Project panel, double-click on LearningScript.
  2. In MonoDevelop, write the lines 6, 11, and 13 from the next screenshot.
  3. Save the file.
Time for action – creating a variable and seeing how it works

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.

  1. Drag LearningScript onto the Main Camera.
  2. Select Main Camera so that it appears in the Inspector panel.
  3. Verify whether LearningScript is attached.
  4. Open the Unity Console panel to view the output of the script.
  5. Click on Play.

The preceding steps are shown in the following screenshot:

Time for action – creating a variable and seeing how it works

What just happened?

In the following Console panel is the result of our equations. As you can see, the equation on line 13 worked by substituting the number 9 for the myNumber variable:

What just happened?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.171.212