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

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 ObjectOriented 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:

  1. In MonoDevelop, select variableScript for editing
  2. Edit the file so that it looks exactly like what is shown in the following screenshot:
  1. 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();.

主站蜘蛛池模板: 深泽县| 井冈山市| 常州市| 都匀市| 石城县| 梅河口市| 水富县| 汕头市| 仪征市| 新河县| 洱源县| 泰州市| 万宁市| 廊坊市| 龙山县| 清涧县| 启东市| 彭州市| 文水县| 锦屏县| 唐山市| 临夏市| 枞阳县| 黔西| 绥滨县| 长垣县| 垦利县| 锦屏县| 谢通门县| 抚顺县| 砀山县| 监利县| 景泰县| 开鲁县| 武乡县| 峨山| 上高县| 桐庐县| 通辽市| 金塔县| 宁明县|