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

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.

主站蜘蛛池模板: 凤山市| 施秉县| 宝鸡市| 金溪县| 普宁市| 将乐县| 大连市| 长春市| 井冈山市| 正蓝旗| 黄骅市| 九龙坡区| 句容市| 浑源县| 宣汉县| 和田市| 韶关市| 朝阳市| 东海县| 彭泽县| 城市| 乐陵市| 商洛市| 合肥市| 罗定市| 盐边县| 马公市| 黑水县| 威远县| 广汉市| 鄄城县| 勃利县| 富锦市| 平陆县| 大化| 保亭| 沙田区| 吴堡县| 湟源县| 黄大仙区| 伊金霍洛旗|