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

Returning a value from a method

Now it's time to discover the "power" feature of using a method. This usually means sending data to the method, which you just learned to do, then have the method return a value back. Previously, all you had the AddTwoNumbers() method do was take the result of adding two numbers and display it to Unity's Console.

Now, instead of displaying the result directly, you're going to modify AddTwoNumbers() to return the result of the addition back to the place the method was called.

Note

Remember, I told you that when you call a method, it's just a substitute for the code block that will be executed. It's like taking all the code in the method's code block and placing it right there where the method was called.

The next screenshot is still very simple, but it shows how this substitution works and how returning a value from a method works.

主站蜘蛛池模板: 阜城县| 泗水县| 庆元县| 普兰店市| 磐石市| 东丽区| 英德市| 漳平市| 长泰县| 堆龙德庆县| 蓬安县| 资阳市| 顺平县| 衡山县| 扶风县| 淳安县| 巫山县| 锡林郭勒盟| 兴业县| 霍城县| 肃北| 石狮市| 九龙城区| 昌黎县| 甘德县| 余姚市| 本溪市| 咸宁市| 巫溪县| 娱乐| 秀山| 大足县| 清丰县| 灵宝市| 深水埗区| 祁东县| 涟水县| 崇礼县| 浦县| 漾濞| 鲁山县|