Question by
rwols · Aug 31, 2016 at 11:12 PM ·
multiplemonobehaviouroverlapinterfaces
What is the general strategy for multiple monobehaviours implementing the same interface?
Suppose we have an interface
interface IDamageTaker
{
void TakeDamageFrom(GameObject damageGiver);
}
And suppose we have a prefab with multiple monobehaviours attached to it that implement the IDamageTaker interface. How do we now apply damage? We could find the first IDamageTaker in the list of components, but then that ignores the others. On the other hand, if we apply damage to all IDamageTakers, that is perhaps unwanted because too much damage is taken.
What is the preferred approach here? Has anyone encountered this problem?
Comment