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

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.

主站蜘蛛池模板: 磴口县| 嘉定区| 家居| 嵩明县| 泽库县| 昌宁县| 当涂县| 马边| 兰考县| 朝阳区| 西安市| 祁门县| 绥阳县| 无锡市| 凤凰县| 尉犁县| 泗水县| 万盛区| 曲阳县| 内黄县| 晴隆县| 大庆市| 惠来县| 镇雄县| 剑川县| 乌兰县| 来安县| 类乌齐县| 黑龙江省| 万载县| 宁阳县| 耒阳市| 文昌市| 隆昌县| 永兴县| 奉节县| 阳春市| 长乐市| 三门县| 余江县| 宜黄县|