- 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.
推薦閱讀
- Learning Python Web Penetration Testing
- Mobile Application Development:JavaScript Frameworks
- Monkey Game Development:Beginner's Guide
- Mastering phpMyAdmin 3.4 for Effective MySQL Management
- AngularJS深度剖析與最佳實踐
- PostgreSQL 11從入門到精通(視頻教學版)
- MATLAB實用教程
- Redis Essentials
- Learning OpenStack Networking(Neutron)
- 軟件品質之完美管理:實戰經典
- Getting Started with Python
- Python 3 Object:oriented Programming(Second Edition)
- OpenCV Android開發實戰
- Docker:容器與容器云(第2版)
- Three.js權威指南:在網頁上創建3D圖形和動畫的方法與實踐(原書第4版)