- Learning C# by Developing Games with Unity 3D Beginner's Guide
- Terry Norton
- 206字
- 2021-08-04 10:03:58
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:

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:

推薦閱讀
- Boost程序庫完全開發指南:深入C++”準”標準庫(第5版)
- 一步一步學Spring Boot 2:微服務項目實戰
- JavaScript修煉之道
- Docker進階與實戰
- Effective C#:改善C#代碼的50個有效方法(原書第3版)
- Java EE框架整合開發入門到實戰:Spring+Spring MVC+MyBatis(微課版)
- PostgreSQL 11從入門到精通(視頻教學版)
- 深入淺出RxJS
- Scala for Machine Learning(Second Edition)
- 零基礎看圖學ScratchJr:少兒趣味編程(全彩大字版)
- 啊哈C語言!:邏輯的挑戰(修訂版)
- PostgreSQL 12 High Availability Cookbook
- Learning ROS for Robotics Programming
- 編寫高質量代碼之Java(套裝共2冊)
- Hands-On Data Visualization with Bokeh