Al Heck

Why Use Interfaces?

We can create a system that scales. We don’t have to hard code everything into our scene. We can assign it a i***able, and it will do whatever that method is regardless of what it is.

Let’s create an iCollectable. The whole purpose is anything using this item uses the collect function (a contract).

Now we create a script that grabs from monobehavior and icollectable. Now I’m going to add a simple function to it — a destroy method to anything this gameobject is attached to.

So now I basically do a getcomponent when I raycast, check if it has the icollectable, and then run the collect() method.

Now if I drop the itemscript onto all of the gameobjects, as I pick them up, they will run the associated script.