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

Watching for a possible gotcha when using public variables

Unity gives us great flexibility with editing or reading public variables in the Inspector tab. You will be using public variables most of the time. Now, I want to make you aware of something that might give you a headache sometimes.

All public variable values are overridden by the Unity Inspector tab.

Let's look back at line 6; we had assigned our variable a value of 9. This value will be copied to the Unity Inspector. From now on, the value from Inspector is taken into account and not the value in the script, even if you change it. Therefore, be careful as this is very easy to forget.

In the Inspector panel, try changing the value of myNumber to some other value, even a negative value. Notice the change in the answer in the Console tab.

主站蜘蛛池模板: 康乐县| 固原市| 凤庆县| 法库县| 四川省| 昂仁县| 和田市| 青阳县| 峨眉山市| 元氏县| 镇平县| 阆中市| 阿拉善左旗| 金溪县| 杨浦区| 礼泉县| 黄石市| 镇宁| 芦山县| 永康市| 邯郸市| 宁津县| 顺平县| 淮阳县| 名山县| 电白县| 灵石县| 阜南县| 公安县| 光山县| 修水县| 垦利县| 萨嘎县| 星座| 收藏| 陆河县| 红河县| 特克斯县| 兖州市| 台州市| 临沭县|