Multiple ref to multiple object with same name and same collider

Hi,

I am currently making a stealth game and to do so I am coding the AI of the bad guys. Everything works fine they each follow their own patch and have a distinc detection (if one sees me the others don’t come unless they are too close).

My big problem is that they all die if I kill one of them, I know where it comes from but I don’t know how to fix it.

First of all you should know I use RAIN for AI so it has specific rules. Here is the script responsible for the AI death :

    public class DeathScript : RAINAction
    {
    	GameObject Character = GameObject.Find ("First Person Controller");
    	BadGuy myScript;
    
        public DeathScript()
        {
          actionName = "DeathScript";
        }
    
        public override void Start(AI ai)
        {
            base.Start(ai);
        }
    
        public override ActionResult Execute(AI ai)
        {
    		myScript = Character.GetComponent<BadGuy>();
    		
    		if (myScript.isDead) {
    			ai.WorkingMemory.SetItem<bool> ("Dead", true);
    				}
    		else
    			ai.WorkingMemory.SetItem<bool> ("Dead", false);
    
            return ActionResult.SUCCESS;
        }
    
        public override void Stop(AI ai)
        {
            base.Stop(ai);
        }
    }

And here is the script attached to my hero :

public class BadGuy : MonoBehaviour {
	public int IDSoldier;
	 bool iSeeYou = false;
	public bool isDead;
	public float BadGuyHP = 100;

	void Update()
	{

		if (BadGuyHP <= 0) {
			isDead = true;
				}
				else 
			isDead = false;

		
	}

	void OnTriggerStay (Collider col)
	{


		if (col.gameObject.tag == "Unit") 
		{
			if(iSeeYou && ObjectGestion.HitKnife)
			{
				BadGuyHP -= 20;
			}
			else if (!iSeeYou && ObjectGestion.HitKnife)
			{
				BadGuyHP -= 100;
			}
		}
	}
}

I HAVE to put my “isDead” as a public to access it on RAIN. And I tried every kind of variable type for BadGuyHP from private to public to static to public in another script to public static in another script. Nothing works so I am really lost here.

I’m not sure how RAIN works but is there a new instance of AI created for each of your BadGuys?

At a glance I would guess that you are setting isDead correctly in the BadGuy class but then setting the AI “Dead” bool to true for all the BadGuys using the same instance of the AI on this line:

ai.WorkingMemory.SetItem<bool> ("Dead", true);

Is there any way you can ensure that a new AI is instantiated for each BadGuy?