Overloading methods in C# & Unity
Objective: Show how to overload a method in C# for my recent game release
When creating my latest game The Departure (available here), I needed a way to call the same method but with different parameters depending on the collectible that the player was picking up.
This lead me to creating a method that has two different sets of parameters and this is called overloading & can also be called polymorphism.
Above you can see the implementation of the methods. The base method takes in two parameters, and the overloaded method takes four parameters.
I have certain collectibles in the game that I wanted to play background music after the player has picked them up. This lead mead towards using polymorphism to pass in different parameters when needed.
For more information about method overloading/overriding and polymorphism in C#, take a look at this article.
If you found this helpful, don’t forget to clap and follow for more articles on game development in Unity.