- Unity 2017 Mobile Game Development
- John P. Doran
- 130字
- 2021-07-02 22:27:44
The Range attribute
Another thing that we can use to protect our code is the Range attribute. This will allow us to specify a minimum and maximum value for a variable. Since we want the player to always be moving forward, we may want to restrict the player from moving backward. To do that, we can add the following highlighted line of code:
[Tooltip("How fast the ball moves forwards automatically")]
[Range(0, 10)]
public float rollSpeed = 5;
Save your script, and return to the editor:

We have now added a slider beside our value, and we can drag it to adjust between our minimum and maximum values. Not only does this protect our variable, it also makes it so our designers can tweak things easily by just dragging them around.
推薦閱讀
- 造個小程序:與微信一起干件正經事兒
- 樂高機器人設計技巧:EV3結構設計與編程指導
- Python深度學習原理、算法與案例
- Mastering Elasticsearch(Second Edition)
- Mockito Essentials
- 美麗洞察力:從化妝品行業看顧客需求洞察
- 軟件開發中的決策:權衡與取舍
- Mastering Machine Learning with scikit-learn
- Visual C++程序開發范例寶典
- Building E-Commerce Solutions with WooCommerce(Second Edition)
- C#編程魔法書
- 計算機教學研究與實踐:2017學術年會論文集
- 快速搞定Spring Boot+Vue全棧開發
- RStudio for R Statistical Computing Cookbook
- HTML5 for Flash Developers