Quantcast
Channel: Questions in topic: "get"
Viewing all articles
Browse latest Browse all 215

Get position for each Gameobject (in array) ?

$
0
0
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(); } 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().PosXFoe - 2; PosZFoe = FoeRes[i].GetComponent().PosZFoe - 2; } } player.transform.position = new Vector3(PosXFoe, 1, PosZFoe); if (FoeHealth.currentHealth > 0 /*attackphas*/) { // ... damage the player. FoeHealth.TakeDamage(attackDamage); } } } Please, help me...

Viewing all articles
Browse latest Browse all 215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>