In the last chapter, we briefly touched on the role methods play in our programs, namely, that they store and execute instructions, just like variables store values. Now we need to understand the syntax of method declarations and how they drive action and behavior in our classes.
Basic syntax
As with variables, method declarations have their own basic requirements, which are as follows:
- The type of data that will be returned by the method
- A unique name starting with a capital letter
- A pair of parentheses following the method name
- A pair of curly brackets marking the method body (where instructions are stored)
Putting all of these rules together, we get a simple method blueprint:
returnType UniqueName()
{
method body
}
Let's break down the default Start() method...