How to associate two objects and execute the same function?

I have a script named Enemy.cs with the function:


There are two enemies ——A and B both with Enemy.cs.

  • When A is killed and executes
    killedByPlayer(),I want B to excute
    killedByPlayer() as well.

  • Vice versa, when B executes
    killedByPlayer(), I want A to excute

How could I reach it? Simply call the other one in killedByPlayer() will end up with an infinite loop.

Actually, I want these two enemies to stay fully synchronized (Other objects to be done in the future). To avoid the infinite loop call, I implemented an extra manager to record the calling status. Now I’m dealing with the Generics.
Thanks for everyone’s help.