Prevent Function from running few times in a frame

I’m in an awkward problem here.

Simple situation: I’ve got few weapons, dealing Raycast Damage to Enemies. When Enemy Health reaches 0, he dies and gives Player X amount of cash(let’s say 15 for example).

All’s good, but the shotgun is acting weird. It fires multiple racasts at the same time (about 10 of them) in the same frame. SO if a shotgun blast kills an enemy, all raycasts are calling ApplyDamage() function in th same frame, which then calls Die() function multiple times (to be exact, the number of Raycasts that hit him in this frame) . This causes the script to run the Die() function multiple times, causing Enemy to drop Reward more than once.

TL;DR / Conclusion:

Is there a way to restrict a Function be called EXACTELY once in a lifetime or only once in a frame (to prevent it from running multiple times in the same frame)?

use a simple boolean as a condition to stop it.

PSEUDO Code

bool bar = false;
void foo() {
   if(bar) return;
   bar = true;

   //Do random function related stuff here :P
}

Unless you’re creating multiple threads this method can be called exactly once at a time.

What I expect is happening is that you have more than one instance of the script (attached to multiple game objects?)

If you want only one instance of the script to be called then make the ‘bar’ be static such:

private static bar = false;
public void foo() {
  if(bar)
  {
    return;
  }
  bar = true;

  //
  // Do code that will only ever be run once
  //
}

Note, this should technically work, but the whole idea of what is going on here seems very strange - I don’t think this is the correct way to solve the initial problem you’re trying to fix. I expect there is a far more elegant way to address this.