官术网_书友最值得收藏!

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.

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:

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:

主站蜘蛛池模板: 洛隆县| 凤山县| 天水市| 万载县| 通城县| 老河口市| 长海县| 武威市| 鱼台县| 高碑店市| 若尔盖县| 海淀区| 临沭县| 汽车| 县级市| 珠海市| 淮滨县| 宁河县| 汉寿县| 永胜县| 阜平县| 连城县| 元阳县| 同德县| 商丘市| 皋兰县| 宜兰县| 平度市| 茂名市| 吉安县| 雷山县| 花垣县| 永吉县| 新昌县| 闽侯县| 隆安县| 商城县| 平湖市| 绍兴县| 昂仁县| 钟山县|