Chapter 4. Getting into the Details of Methods
In the previous chapter, you were introduced to a variable's scope—where a variable exists and is allowed to be used. The scope is determined by the "opening" and "closing" curly braces. The purpose of those curly braces is to act as a container for a block of executable code, a code block. In second chapter you saw that a method is a code block that can execute by just calling the method's name. It's time to see the importance of code blocks and the variables used in them. A method defines a code block which begins and ends with curly braces.
In this chapter we will cover the features of methods:
- Ending method definitions with curly braces
- Using methods in a script
- Naming methods properly
- Defining a method
- Calling a method
- Returning a value from a method
- Using Unity's
Update()
andStart()
methods
Variables are the first major building block of C#, methods are the second, so let's dive...