Destructible

Implements from IDamageable, so it can be damaged and destroyed.

This component must be added to ANY destructible object in your environment. However, you might want to check other examples such as Crate.cs or ExplosiveBarrel.cs. Although they are different objects with different functionalities, both are destructible and can be destroyed. How does this work? Their custom scripts inherit from Destructible.cs, which in turn inherits from MonoBehaviour and implements IDamageable. So, even though they perform different actions, they are fundamentally the same type of object. Since Die() is a virtual void method, you can override it in your custom script that inherits from this one.

  • maxHealth: Initial health of the destructible"

  • lootInside: Instantiate something cool when the object is destroyed, such as coins, a weapon, or any kind of loot, whatever you want! If this is empty, no reward will be instantiated

  • destroyedSFX: AudioClip to play on destruction.

Functions & Accesors | Destructible.cs

Damage ( float damage, bool isHeadshot )

Damages the IDamageable

  • damage: Damage to apply on the IDamageable

  • isHeadshot: Generally false for Destructibles.

Die( )

Destroys the Destructible

Last updated