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.

--

--

--

Unity Developer and Software Engineer who loves making games with GameDevHQ

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why are Screen Space Reflections Unique?

IBM Sterling SFTP Server Adapter 2.0 vs. SFTP Server Adapter 1.0: Performance Comparison

Create your HDRP Project and import into your scene

Why don’t developers use TDD in practice

Ultimate Guide on How to hire Flutter developer

Ultimate Guide on How to hire Flutter developer

[ML UTD 35] Machine Learning Up-To-Date — Life With Data

UI and UX in Cordova

Mayfield CIO Insight Forum with Guest Speaker Ben Golub

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Al Heck

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ

More from Medium

ABAP Object-Oriented Shorts: Class Visibility

The four stages of the gcc compiler: preprocessor, compiler, assembler, linker.

Tradocaps | World’s First Smart Traders Platform

All you need to know about Concurreny in Golang