In part 2 of our multi-part game audio programming series, Brennan shows us how to add pitch and volume changes to a sound within a game. We have included a list of programming terms used in this video below, to help you follow along.
Function Overload: A function overload is when you declare two functions with the same name, but each takes different arguments. This allows you to change the implementation of your code without having to create different function names. When calling a function, if you have multiple overloads, the autocomplete will tell you which overload will be chosen based on the data you are passing into the arguments.
Float: A float or floating point number is the data type used for decimal numbers in a game engine. These numbers are always approximated. Any time you want a whole number, you will use a different data type called an int.
Default Values / Optional Arguments: When creating a function, you can set any argument to a default value, making it an optional argument. In a function, an argument must always have some value associated with it otherwise the compiler will give you an error. Sometimes though, you may not want to always put in a value when calling the function, because it might be the same every time. For example if you had a function PlaySound(sound, 1f), where the 1f was the volume, nearly every sound might be played at 1f and only a couple would be different. You can set the volume argument to default to 1f so that when you call the function you can mostly just type in PlaySound(sound). You would only need to type in a separate argument if you wanted the value to be anything other than 1f.
Assignment Operator: Often you will see the = symbol in code. This does not mean “is equal to”! This actually means “is set to”. This is an assignment operator used to set the values of variables. If you are doing conditional checking and want to use “is equal to”, you need to use ==, or “double equals”.
Instantiate: In Unity you can instantiate, or create, a game object during play.
Get Component: This will give you access to a specific component or class on a GameObject.
More from the Blog