IKillable - jimdroberts/FishMMO GitHub Wiki
Interface for entities that can be killed by a character or other source. Implement this to allow objects to be killed and trigger death logic.
-
void Kill(ICharacter killer)
Kills the entity, triggering death logic and effects. killer (ICharacter): The character responsible for the kill.
- Implement IKillable on your entity or object class.
- Provide logic in the Kill method to handle death, cleanup, and effects.
- Use the interface to allow characters or other sources to kill the entity.
// Example 1: Implementing IKillable
public class Enemy : MonoBehaviour, IKillable {
public void Kill(ICharacter killer) {
// Death logic here
}
}
// Example 2: Killing an entity in gameplay
IKillable target = enemy.GetComponent<IKillable>();
target.Kill(player);
- Always implement the Kill method to handle all relevant death logic for your entity.
- Use IKillable for all objects that should be affected by lethal effects or attacks.
- Trigger cleanup, animations, and effects in the Kill method as needed.