- Learning C# by Developing Games with Unity 3D Beginner's Guide
- Terry Norton
- 150字
- 2021-08-04 10:04:02
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.
推薦閱讀
- 極簡(jiǎn)算法史:從數(shù)學(xué)到機(jī)器的故事
- Java異步編程實(shí)戰(zhàn)
- Visual Basic編程:從基礎(chǔ)到實(shí)踐(第2版)
- Web交互界面設(shè)計(jì)與制作(微課版)
- 匯編語言程序設(shè)計(jì)(第2版)
- 單片機(jī)應(yīng)用技術(shù)
- JavaScript從入門到精通(第3版)
- Learning ArcGIS for Desktop
- Windows內(nèi)核編程
- R用戶Python學(xué)習(xí)指南:數(shù)據(jù)科學(xué)方法
- Java零基礎(chǔ)實(shí)戰(zhàn)
- 平面設(shè)計(jì)經(jīng)典案例教程:CorelDRAW X6
- Clojure for Java Developers
- Learning Ionic
- Scratch從入門到精通