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

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.

主站蜘蛛池模板: 镇宁| 琼中| 新平| 天峻县| 江陵县| 沅江市| 高邮市| 秦皇岛市| 旬邑县| 安溪县| 瑞丽市| 滕州市| 阿荣旗| 桦南县| 普定县| 喀什市| 郯城县| 砚山县| 鲁山县| 稻城县| 阿勒泰市| 郎溪县| 将乐县| 满洲里市| 哈尔滨市| 海门市| 平泉县| 双江| 庆阳市| 乐都县| 江西省| 翁牛特旗| 南投市| 海盐县| 靖宇县| 偏关县| 斗六市| 开封县| 乐清市| 商南县| 商水县|