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

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.

主站蜘蛛池模板: 滦南县| 改则县| 顺义区| 凤城市| 玛沁县| 九江县| 莎车县| 仙居县| 团风县| 环江| 获嘉县| 台中县| 溧水县| 永福县| 尼玛县| 航空| 井研县| 哈巴河县| 温州市| 云霄县| 湖南省| 乐业县| 利川市| 鄯善县| 黄大仙区| 五原县| 康保县| 柏乡县| 古浪县| 阳原县| 卓尼县| 习水县| 南召县| 曲沃县| 新和县| 天长市| 买车| 临沧市| 深圳市| 简阳市| 东安县|