官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 大同县| 金门县| 拉孜县| 宣化县| 大连市| 任丘市| 杭锦后旗| 沁水县| 华宁县| 长泰县| 革吉县| 宁德市| 乌兰县| 太谷县| 梅州市| 普格县| 松江区| 柯坪县| 台北县| 庄河市| 三门县| 新蔡县| 稻城县| 芒康县| 乌什县| 沿河| 舒兰市| 顺昌县| 郯城县| 瑞昌市| 梅河口市| 张家口市| 黔东| 云梦县| 桂阳县| 江门市| 海门市| 绥芬河市| 大石桥市| 宿松县| 日土县|