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.

  1. Open LearningScript in MonoDevelop to modify it.
  2. On line 12, declare the answer variable (this statement is on 3 lines).
  3. On lines 19 to 23, redefine the AddTwoNumbers() method with a return type.
  4. On lines 25 to 28, define the DisplayResult() method.
  5. Save the file.
  6. Click on Play in Unity.
Time for action – returning a value from AddTwoNumbers()

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.