- Home /
This question was
closed May 01, 2016 at 07:20 PM by
Cherno.
Question by
deglet · May 01, 2016 at 04:38 PM ·
gameobjectarraypositionget
Get position for each Gameobject (in array) ?
Hello, I am making a game and I have two scripts (s_PlayerControl for the player, and s_EnnemyControl for the enemy). My enemy is a prefab who spawn regularly. I try to get the position of each clone in order to attack them. But I can't get the position.
public class s_PlayerControl : MonoBehaviour{
//--------------------------------------------VAR------------------------------------
public GameObject Player = GameObject.Find("o_player");
public GameObject Foe = GameObject.Find("Foe_01");
public GameObject[] FoeRes = GameObject.FindGameObjectsWithTag("Foe");
}
then
void Start()
{
FoeHealth = Foe.GetComponent<s_EnnemyControl>();
}
And the attack:
void GestureAttack()
{
if (recupgeste == "D" && recupgestescore > 0.60)
{
invincible = true;
for (int i = 0; i < 100; i++)
{
foreach (GameObject Foe in FoeRes)
{
PosXFoe = FoeRes[i].GetComponent<s_EnnemyControl>().PosXFoe - 2;
PosZFoe = FoeRes[i].GetComponent<s_EnnemyControl>().PosZFoe - 2;
}
}
player.transform.position = new Vector3(PosXFoe, 1, PosZFoe);
if (FoeHealth.currentHealth > 0 /*attackphas*/)
{
// ... damage the player.
FoeHealth.TakeDamage(attackDamage);
}
}
}
Please, help me...
Comment