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

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.

主站蜘蛛池模板: 繁峙县| 日土县| 永福县| 玛纳斯县| 武强县| 扎兰屯市| 阿拉善右旗| 偃师市| 连云港市| 临海市| 宁城县| 嵩明县| 临清市| 永吉县| 城固县| 常州市| 鹿泉市| 马尔康县| 定日县| 亳州市| 鄂伦春自治旗| 平果县| 静乐县| 西华县| 海原县| 玉田县| 成安县| 新河县| 翼城县| 达拉特旗| 龙州县| 谢通门县| 科尔| 揭西县| 峨眉山市| 布拖县| 峨边| 阿拉善盟| 孟村| 蒙自县| 马龙县|