Kill one enemy they all dies?

Hi

The problem with my code is that when i fire at a enemy, they all take damage. They all using the same “enemy” tag, and according to other treads i guess i somehow need to turn each enemy into something other than static. Im not really sure how to do this. I tried to put "public#34; and/or “private&” in front of each related variabel (“var”), but that did not made any diffrence.

This is the code fore the bullet:

var maxDist : float = 1000000;
var decalHitWall : GameObject;
var floatInFrontOfWall : float = 0.0001;
var damage : float = 1;

var GetFSM : PlayMakerFSM; 
GetFSM = gameObject.Find("Maltavla").GetComponent.<PlayMakerFSM>(); 

function Update () 

{
   var hit : RaycastHit;
   if (Physics.Raycast(transform.position, transform.forward, hit, maxDist))
   {
      if (decalHitWall && hit.transform.tag == "LevelParts")
          Instantiate(decalHitWall, hit.point + (hit.normal * floatInFrontOfWall), Quaternion.LookRotation(hit.normal));
      if (hit.transform.tag == "Enemy")
      
      {
         hit.transform.GetComponent(EnemyBodyScript).enemyHealth -= damage;
         // GetComponent(EnemyBodyPartsScript).enemyBody.
                
      }
     
 
                if (hit.transform.tag == "EnemyHead")
               
               {// activate playmaker event "headshot"
                  GetFSM.Fsm.Event("HeadShot");
                
               }
               
   }
   Destroy(gameObject);
}

And this is the code i use for the enemy:

var enemyHealth : float = 10;
var enemyHeadHealth : float = 1;

var GetFSM : PlayMakerFSM;
GetFSM = gameObject.Find("Maltavla").GetComponent.<PlayMakerFSM>();

function Update () 

{
  if (enemyHealth <= 0)
  // activate playmaker event 
                  GetFSM.Fsm.Event("Killed");  

As you can see im also using playmaker.

Regards,

found some error in your second code piece:

GetFSM = gameObject.Find("Maltavla").GetComponent.<PlayMakerFSM>();

this founds ANY gameobject named “Maltavla”

  if (enemyHealth <= 0) GetFSM.Fsm.Event("Killed"); 

and this kills it checking LOCAL variable enemyHealth

but how do you map enemyHealth to GetFSM? is this enemyHealth for THIS GetFSM&

Hi
Thank you for the replay, but i dont really understand your question.
This is the enemy life, its 10:

var enemyHealth : float = 10;

and this is the damage that is being made once the bullets raycast reach the enemy:

var damage : float = 1;

" GetFSM = gameObject.Find(“Maltavla”).GetComponent.();

this founds ANY gameobject named “Maltavla” "

  • Yes it does, what i need is a code to find only the one gameobject that was hit

ScroodgeM: Your idea seems to work! Thank you :smiley: