- Learning C# 7 By Developing Games with Unity 2017(Third Edition)
- Micael DaGra?a Greg Lukosek
- 361字
- 2021-07-02 19:59:38
Using the term "method" instead of "function"
You are going to see the words "function" and "method" used everywhere as you learn how to code.
The words "function" and "method" truly mean the same thing in Unity. They also do the same thing.
Since you are studying C#, and C# is an Object–Oriented Programming (OOP) language, I will use the word method throughout this book, just to be consistent with C# guidelines. It makes sense to learn the correct terminology for C#. The authors of Scripting Reference probably should have used the word "method" instead of "function" in all of their documentation. Anyway! Whenever you hear either of these words, remember that they both mean the same thing.
From now on, I'm going to use the word method or methods in this book. When I refer to the functions shown in Scripting Reference, I'm going to use the word "method" instead, just to be consistent.
We're going to edit the variableScript again. In the following screenshot, there are a few lines of code that look strange. We are not going to get into the details of what they mean in this chapter. We will discuss that in Chapter 4, Getting into the Details
of Methods. Right now, I am just showing you a method's basic structure and how it works:
- In MonoDevelop, select variableScript for editing
- Edit the file so that it looks exactly like what is shown in the following screenshot:

- Save the file
In the previous screenshot, lines 6 and 7 will look familiar to you. They are variables, just as you learned in the previous section. There are two of them this time. These variables store the numbers that are going to be added.
Line 16 may look very strange to you. Don't concern yourself right now with how it works. Just know that it's a line of code that lets the script know when the Enter key is pressed. On the keyboard method, AddTwoNumbers will be called into action.
The simplest way to call a function in your code is by using its name followed by brackets and a semicolon, for example, AddTwoNumbers();.
- JavaScript修煉之道
- 華為HMS生態與應用開發實戰
- R語言數據可視化實戰
- Windows Presentation Foundation Development Cookbook
- C++ 從入門到項目實踐(超值版)
- Android Native Development Kit Cookbook
- HTML 5與CSS 3權威指南(第3版·上冊)
- C語言程序設計
- Python3.5從零開始學
- 軟件供應鏈安全:源代碼缺陷實例剖析
- Regression Analysis with Python
- Lift Application Development Cookbook
- .NET 4.0面向對象編程漫談:應用篇
- SSH框架企業級應用實戰
- 基于Docker的Redis入門與實戰