Let's open up LearningCurve again and see how a method works in C#. Just like with the variables example, you'll want to copy the code into your script exactly as it appears in the following screenshot. I've deleted the previous example code to make things neater, but you can, of course, keep it in your script for reference:
- Open up LearningCurve in Visual Studio and add in lines 8, 13, and 16 - 19.
- Save the file, and then go back and hit Play in Unity to see the new Console output:
You defined your first method on lines 16 to 19 and called it on line 13. Now, wherever AddNumbers() is called, the two variables will be added together and printed to the console, even if their values change:
Go ahead and try out different variable values in the Inspector panel to see this in action! More details on the actual code syntax of what you just wrote are coming up in the next chapter.
With a bird's-eye view of methods under our belts, we're ready to tackle the biggest topic in the programming landscape – classes!