O'Reilly logo

Learning C# by Developing Games with Unity 3D Beginner's Guide by Terry Norton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required