Allows us to force inheritance for easy coding! For this example, we want to create an employee salary system. We want to force every employee to calculate monthly salary so we set the function to abstract and since we did that, we have to force our class to be abstract as well.
Next, we will create a new class that is part-time that will inherit employee. Since we grabbed a class that also uses monobehavior, we inherited the Employee class and the Monobehavior class. Because it’s pulling from an abstract class, we need to do an override function for calculateMonthlySalary(). We will also add the variables for hours worked and hour rate.
Let’s loop through a item dictionary. This is useful for a loop vs a simple list or an array because sometimes, the count can be huge. 10 is not large. To cycle through 60,000 or 6,000,000 can be time consuming. Let’s see if we can use dictionaries to find the item based on the key id. To start, let’s create a dictionary item DB.
All of these items have been added via script into our database. Now we can sort through this list using library keys.
Let’s do a foreach loop.
Sometimes, you can’t pass a string. Enums still come in similar to arrays, so how do we get the int value of an enum?
To cast it, we need to add a (int) in front of the variable amount.
This allows us to grab the numerical value of the enum over the string value. This is great for a level selection system.