How do I award exp to the character that made the kill?

I’ve been struggling to award the player exp only for the kills they made themselves. I have a working exp level up system but am stuck in determining who made the killing stroke when several npcs and potentially other players are in the scene. Currently the system awards the player whenever an NPC dies. But this doesn’t factor in other hostile characters and/or npcs. Any suggestions in c# please? Again simply awarding exp to the player when an npc dies is not the question. One method might be to set a flag on an NPC when successfully hit and the last character to have set the flag before death gets the exp. At first I’ve attempted to do this by setting a public bool on the NPC but 1) can’t seem to effect the bool via another script without resorting to a getcomponent search. 2) This doesn’t allow multi players or npcs getting exp. After many hours of failed scripting trying to accomplish this I’m looking for a script suggestion that isn’t a quick and dirty fix but rather an elegant solution going forward to allow versioning where more than just a single player gets exp.

So I might do something like the following. I’m assuming a bunch of stuff, based on the code that was at one point posted. I’ve also coded this thing up right here, which just means I’ve not compiled it or looked at the stack reference page to make sure I’ve done it right… but I think it should be fine.

    /// assuming parent class is a monobehaviour shared
    /// between the damager and that which is being damaged.
    public class SubClass : ParentClass  
    {
      // int is probably fine, though
      private float health;
      private Stack<ParentClass> damagers;

      // int is probably fine here, too
      public void TakeDamage(float damage, ParentClass sender)
      {
         this.health -= damage;
         this.damagers.push(sender);
         // TODO: whatever else you feel is a good idea
      }

      public void Update()
      {
         if(this.health <= 0)
         {
            var winner = damagers.peek();
            winner.ApplyXP(/*some value*/);
            // TODO: whatever else you want to do when a thing dies.
         }
      }
    }