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

Using methods in a script

There are two reasons for using methods in a script:

  • To provide behavior to a GameObject
  • To create reusable sections of code
Note

All of the executable code in a script is in methods.

The first purpose of a method is to work with the member variables of the class. The member variables store data that's needed for a Component to give a GameObject its behavior. The whole reason for writing a script is to make a GameObject do something interesting. A method is the place we make the behavior come to life.

The second purpose of a method is to create code blocks that will be used over and over again. You don't want to be writing the same code over and over. Instead, you place the code into a code block and give it a name so you can call it when needed.

主站蜘蛛池模板: 华坪县| 黄大仙区| 崇礼县| 社会| 芷江| 衡山县| 那坡县| 普兰店市| 曲周县| 棋牌| 恩施市| 华安县| 洛浦县| 五莲县| 宣城市| 彭水| 洞口县| 波密县| 普安县| 文昌市| 行唐县| 巩义市| 刚察县| 东阿县| 伊宁市| 桦南县| 荥阳市| 廉江市| 安新县| 西林县| 高陵县| 科尔| 云南省| 涿州市| 靖江市| 长沙市| 长泰县| 抚顺县| 秦皇岛市| 南汇区| 忻州市|