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,