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

The Tooltip attribute

If you've used Unity for a period of time, you may have noted that some components in the Inspector window, such as the Rigidbody, have a nice feature--if you move your mouse over a variable name, you'll see a description of what the variables are and/or how to use them. The first thing you'll learn is how we can get the same effect in our own components by making use of the Tooltip attribute. If we do this for the dodgeSpeed and rollSpeed variables, it will look something like this:

[Tooltip("How fast the ball moves left/right")] 
public float dodgeSpeed = 5;

[Tooltip("How fast the ball moves forwards automatically")]
public float rollSpeed = 5;

Save the preceding script and return to the editor:

Now, when we highlight the variable using the mouse and leave it there, the text we placed will be displayed. This is a great habit to get into, as your teammates can always tell what it is that your variables are being used for.

For more information on the Tooltip attribute, check out, https://docs.unity3d.com/ScriptReference/TooltipAttribute.html.

主站蜘蛛池模板: 新乐市| 桐城市| 尉犁县| 瓮安县| 承德县| 凤庆县| 珠海市| 石河子市| 云浮市| 延长县| 定兴县| 吉林省| 彰化市| 金塔县| 绥芬河市| 咸丰县| 三明市| 太谷县| 大荔县| 青田县| 河西区| 阿鲁科尔沁旗| 江陵县| 阜新市| 昆明市| 静乐县| 赤水市| 池州市| 平安县| 保德县| 方城县| 兴隆县| 邓州市| 广南县| 离岛区| 巢湖市| 闵行区| 阳新县| 和平区| 扎鲁特旗| 平南县|