Time for action – returning a value from AddTwoNumbers()
Modify LearningScript
to call the
AddTwoNumbers()
method twice and get a grand total. Also create another method whose sole purpose is to display the grand total result.
- Open
LearningScript
in MonoDevelop to modify it. - On line 12, declare the answer variable (this statement is on 3 lines).
- On lines 19 to 23, redefine the
AddTwoNumbers()
method with a return type. - On lines 25 to 28, define the
DisplayResult()
method. - Save the file.
- Click on Play in Unity.
What just happened?
As you can see in the following screenshot, the result is 14. However, the main concept to learn from this example is this: ...
Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.