- Learning C# 7 By Developing Games with Unity 2017(Third Edition)
- Micael DaGra?a Greg Lukosek
- 146字
- 2021-07-02 19:59:37
Watching for a possible gotcha when using public variables
Unity gives us great flexibility with editing or reading public variables in the Inspector tab. You will be using public variables most of the time. Now, I want to make you aware of something that might give you a headache sometimes.
All public variable values are overridden by the Unity Inspector tab.
Let's look back at line 6; we had assigned our variable a value of 9. This value will be copied to the Unity Inspector. From now on, the value from Inspector is taken into account and not the value in the script, even if you change it. Therefore, be careful as this is very easy to forget.
In the Inspector panel, try changing the value of myNumber to some other value, even a negative value. Notice the change in the answer in the Console tab.
推薦閱讀
- 數據結構(C語言)
- HTML5+CSS3+JavaScript Web開發案例教程(在線實訓版)
- Instant Ext.NET Application Development
- Windows內核編程
- Java實戰(第2版)
- 速學Python:程序設計從入門到進階
- 現代C++編程實戰:132個核心技巧示例(原書第2版)
- 計算機應用基礎教程(Windows 7+Office 2010)
- Arduino Wearable Projects
- 貫通Tomcat開發
- C#程序設計基礎入門教程
- 視窗軟件設計和開發自動化:可視化D++語言
- Professional JavaScript
- 計算機常用算法與程序設計教程(第2版)
- 微信公眾平臺服務號開發:揭秘九大高級接口