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

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.

主站蜘蛛池模板: 湘乡市| 邢台市| 鄂托克旗| 汕头市| 清远市| 玉山县| 曲周县| 新竹县| 万源市| 凤冈县| 邯郸市| 光泽县| 宣威市| 东海县| 龙里县| 凤山市| 崇明县| 罗平县| 西青区| 义乌市| 台山市| 玛曲县| 图片| 象山县| 沙坪坝区| 司法| 浦城县| 宣城市| 东山县| 铜梁县| 岳池县| 资源县| 灵川县| 尉氏县| 临汾市| 耿马| 天镇县| 社旗县| 丹东市| 佛冈县| 德兴市|