Abstract Classes and Methods

Al Heck
Oct 22, 2021

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.

We can also create our Fulltime Employee script

--

--

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ