Intro to Methods and Functions

Objective: understand the difference between methods and functions and how to use them.

Today we are going back to the basics. What are methods and functions? They are interchangeable in C# but are more commonly referred to as methods. A method is an encapsulated piece of code i.e. void start and void update.

In these tutorials we create our own custom methods.

private means only the class it is in can access this method. Public enables script communication where a different script can call the method. If you don’t put private or public Unity will default to private.

You call on a method by using the name and parenthesis and initializing with a semi-colon.

This method we are using as an example is known as a void no return function. Void means it runs from top to bottom, it doesn’t return anything, so it is void.

That covers the basics of void no return methods. These basics will help you build your game. As I always say, don’t be afraid to experiment with your code and I’ll see you in the next tutorial!