IDamagable Interface in Unity

Objective: Set up an IDamagable Interface

Currently our Player can pass through the Skeleton and hit it with the sword and nothing really happens. It does register a collision but there is no logic for damage or effect. Let’s fix that. The Skeleton Hit animation was set up following the same splice and transition process as the other animations.

To set up the Interface, create a script called IDamagable(naming structure being I for interface, the name of the script, able at the name), change class to interface and remove the inherits from MonoBehaviour. Next we will use a Health property and Damage method. That’s it for now, nice and simple but we may enhance it later.

Next to use it in the Skeleton we implement the IDamagable interface. We need to set the Health property and add the Damage method or we’ll get an error from not implementing the interface traits. Once this is set up, we are now ready to apply damage to the Skeleton.





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

Recommended from Medium

Akash and Missing Class Codechef Solution | MARCH CHALLENGE

Akash and Missing Class Codechef Solution | MARCH CHALLENGE

Fix Kubernetes / k3s DNS on Oracle Cloud

Where is my Python installed?

Machine learning for production — introducing D ONE’s MLOps repository

Preparing digital John Lewis for peak events — Live Load Tests

Check us OUT..

Can ISA95 Standards Apply to Industry 4.0?

[Part 6] Menentukan Record Name Odoo

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
Simon Leen

Simon Leen


More from Medium

Coroutines in Unity

Easy Way to Make an Audio Slider

Galaxy Shooter 2D — New Enemy Type (chained)

Guide to Terrains in Unity