Hello,
I have a prefab of enemies who spawn regularly. I try to get the position of them in order to kill them.
It work with the one already instanciate but not the new.
First I get the gameobject and the position from the enemy script:
public GameObject Foe = GameObject.Find("o_foe");
public float PosXFoe;
public float PosZFoe;
Then:
void Start()
{
Foe = GameObject.FindGameObjectWithTag("Foe");
FoeHealth = Foe.GetComponent();
}
void Update()
{
PosXFoe = GameObject.Find("o_foe").GetComponent().PosXFoe - 2;
PosZFoe = GameObject.Find("o_foe").GetComponent().PosZFoe - 2;
}
And the attack:
void GestureAttack()
{
if (recupgeste == "D" && recupgestescore > 0.50)
{
player.transform.position = new Vector3(PosXFoe, 1, PosZFoe);
if (FoeHealth.currentHealth > 0 /*attackphas*/)
{
// ... damage the player.
FoeHealth.TakeDamage(attackDamage);
}
}
}
Help me, thanks.
↧