Search Unity

Ragdoll spawned twice

Discussion in 'Scripting' started by Kondor0, Apr 6, 2011.

  1. Kondor0

    Kondor0

    Joined:
    Feb 20, 2010
    Posts:
    601
    Hi

    I have a kind of funny error. I made an enemy soldier for a project and i have different colliders (triggers) in his arms, torso, head, etc. so he can receive different amounts of damage depending on where i shoot him (these hitboxes detect the damage and send a message to the soldier with the damage changed according to the location of the hit).

    The problem is if i shoot him with a shotgun at close distance, he could receive damage in two or more points at the same time so he "dies twice". This shouldn't be a problem except for the fact that two ragdolls-corpses are instantiated at the same time (lol death mitosis).

    Does anyone have any idea to avoid this? how can i make sure that a script doesn't get executed twice at the same time?

    Regards.
     
  2. shaderx

    shaderx

    Joined:
    May 9, 2010
    Posts:
    65
    if you don't need the script after that point use Destroy(this);
     
  3. Kondor0

    Kondor0

    Joined:
    Feb 20, 2010
    Posts:
    601
    The ragdoll spawning is after calling Destroy so that's not the problem.
     
  4. Kondor0

    Kondor0

    Joined:
    Feb 20, 2010
    Posts:
    601
    Anyone? please?
     
  5. siegeon

    siegeon

    Joined:
    Nov 23, 2010
    Posts:
    81
    Sure add a new bool to the class called _alreadyDestoryed, init it to false, then in where you instantiate a new corpse check for the destroyed bool.

    Code (csharp):
    1.  
    2. if(_destroyMessageRecived  !_alreadyDestoryed)
    3. {
    4.       _alreadyDestoryed = true;
    5.      Instantiate(theCorpse)
    6. }
    7.