- 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.
推薦閱讀
- GeoServer Cookbook
- SpringMVC+MyBatis快速開發與項目實戰
- MySQL 8從入門到精通(視頻教學版)
- PHP 7底層設計與源碼實現
- Java入門很輕松(微課超值版)
- Django Design Patterns and Best Practices
- Essential Angular
- Java Web應用開發技術與案例教程(第2版)
- PHP 7+MySQL 8動態網站開發從入門到精通(視頻教學版)
- C# Multithreaded and Parallel Programming
- Python商務數據分析(微課版)
- Software-Defined Networking with OpenFlow(Second Edition)
- Mastering Leap Motion
- micro:bit軟件指南
- Implementing NetScaler VPX?(Second Edition)