Defining a method the right way
Just as with 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," or even, "We have to implement a method." Which is correct? In C#, it doesn't make any difference. Use whichever term helps you learn more easily. 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, that a method will return to the place from where it was called
- The name of the method should be followed by a pair of parentheses
- A pair of curly braces should be present to contain the code block:
returnDataType NameOfTheMethod ( ) { }
At this point, we already know that when we create a new script, there are two methods that always appear by default,...