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

Changing variables

Since myNumber is a variable, the value that it stores can vary. If we change what is stored in it, the answer to the equation will also change. Follow these steps:

  1. Stop Unity by pressing the Stop button and change 9 to 19 in the Unity Inspector tab
  2. Notice that when you restart the game, the answer will be 30

I bet you have noticed the public keyword at the very beginning of the line that declares the myNumber variable. Let me explain what it means. It's called an access modifier. We use these to specify the accessibility of a variable. The public keyword means that the variable can be seen by code outside our script. Look again at the Unity Inspector tab. You can see the value of myNumber there because it is public. The private keyword, however, means that the variable can be accessed only by code in the same class.

Private variables are not visible in the Unity Inspector tab. If you wish to control or view them, make them public.

主站蜘蛛池模板: 徐汇区| 泉州市| 焦作市| 洪雅县| 景谷| 鹰潭市| 滦平县| 台州市| 西乡县| 阿鲁科尔沁旗| 荥阳市| 共和县| 华池县| 博野县| 章丘市| 赣州市| 扎赉特旗| 临桂县| 九江县| 嵊州市| 保德县| 都兰县| 浑源县| 九龙城区| 陇南市| 沾化县| 泰顺县| 六安市| 沽源县| 临湘市| 颍上县| 阿克苏市| 马尔康县| 鹤峰县| 涿鹿县| 周口市| 静乐县| 武清区| 玉林市| 阿拉善左旗| 信阳市|