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

Testing conditions with an if statement

If, if, if. If I do this… if I do that… What happens if…

Certainly you've had to make decisions about all kinds of things in your life every day. We all do it all the time without actually giving the process of making a decision much thought, if any. As we make daily decisions, most of the time we just do the decision processing in our head. Unity doesn't have that human luxury, so we have to write it out so Unity can know the conditions that lead to certain choices. Having to write the logic is the strange part of writing code for beginners, simply because people usually make the vast majority of decision without writing anything down first. However, it is very simple to do.

An if statement is the most common way GameObjects make decisions. Data used to make these decisions is the information usually stored in some variables. For an if statement it's as easy as saying "If my condition is met, then execute my code block."

Testing if conditions are true or false

A sampling of conditions that can be true or false:

  • The user pressed a button
  • The temperature is cold
  • The character died
  • The bear made big potty in the woods

General questions like these are answered by humans, usually, with either a yes or no. For Unity, the answers will be either true or false. For example: "the bear made big potty in the woods" is either true, or false.

主站蜘蛛池模板: 花垣县| 鲁山县| 安溪县| 金塔县| 巫溪县| 宁德市| 绥中县| 张家口市| 若尔盖县| 蒙山县| 泽州县| 儋州市| 清苑县| 平安县| 鹤山市| 来安县| 水富县| 榆树市| 阿坝县| 嘉善县| 静安区| 台湾省| 石渠县| 行唐县| 咸宁市| 西青区| 常山县| 龙里县| 凤山市| 遵化市| 舟曲县| 岐山县| 刚察县| 恩平市| 平舆县| 阿鲁科尔沁旗| 黔西县| 浦北县| 如东县| 深水埗区| 安岳县|