IDamageable - jimdroberts/FishMMO GitHub Wiki
Interface for entities that can receive damage from attacks. Implement this to allow objects to be damaged by characters or other sources.
-
void Damage(ICharacter attacker, int amount, DamageAttributeTemplate damageAttribute, bool ignoreAchievements = false)
Applies damage to the entity. attacker (ICharacter): The character dealing the damage. amount (int): The amount of damage to apply. damageAttribute (DamageAttributeTemplate): The type of damage being applied (e.g., fire, physical). ignoreAchievements (bool): If true, achievement progress is not affected by this damage event.
- Implement IDamageable on your entity or object class.
- Provide logic in the Damage method to handle receiving and processing damage.
- Use the interface to allow characters or other sources to apply damage to the entity.
// Example 1: Implementing IDamageable
public class Enemy : MonoBehaviour, IDamageable {
public void Damage(ICharacter attacker, int amount, DamageAttributeTemplate damageAttribute, bool ignoreAchievements = false) {
// Apply damage logic here
}
}
// Example 2: Applying damage in gameplay
IDamageable target = enemy.GetComponent<IDamageable>();
target.Damage(player, 50, fireAttribute);
- Always implement the Damage method to handle all relevant damage logic for your entity.
- Use the ignoreAchievements parameter to control whether damage should affect achievement progress.
- Use IDamageable for all objects that should be affected by attacks or damaging effects.