Defining a method properly
Just like for variables, we have to let Unity know about a method before we can use it.
Depending on who you talk to, some will say we have to declare a method, others will say we have to define a method. Which is correct? In C#, it doesn't make any difference. Use which ever term helps you learn easier. I like to say I'm defining a method's code block, nothing like declaring a simple variable on a one line statement.
The minimum requirements for defining a method
There are three minimum requirements for defining a method:
- The type of information, or data, a method will return to the place where the method was called
- The name of the method should be followed by a pair of parentheses
- A pair of curly braces should be present for containing the code block:
returnDataType NameOfTheMethod ( ) { }
Looking at LearningScript
once again, or any Unity generated script, the Start()
method has the three bare-bone minimum requirements for a method:
void Start () {...