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.