- 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.
推薦閱讀
- Learn ECMAScript(Second Edition)
- ASP.NET MVC4框架揭秘
- C語言程序設計教程(第2版)
- Mastering Scientific Computing with R
- TypeScript圖形渲染實戰:基于WebGL的3D架構與實現
- Spring實戰(第5版)
- JavaCAPS基礎、應用與案例
- Python之光:Python編程入門與實戰
- C語言開發基礎教程(Dev-C++)(第2版)
- Learning Apache Cassandra
- Mastering JavaScript
- Learning Apache Thrift
- Spring MVC Blueprints
- Flutter for Beginners
- 米思齊實戰手冊:Arduino圖形化編程指南