Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Since my enemies are in a prefab they don't lose health

$
0
0
Hello guys ! I am making a game, and I have a player you can translate on enemies to kill them but since the foes are instantiate with a prefab and a spawnpoint I can't hit them. Maybe because the health isn't in an array. But I can't manage to do it. The foe Health is from there script. GameObject GestureAttack() { //Get all the foes GameObject[] Foes = GameObject.FindGameObjectsWithTag("Foe"); GameObject closest = null; float distance = Mathf.Infinity; Vector3 position = transform.position; //Find the nearest to attack him foreach (GameObject go in Foes) { Vector3 diff = go.transform.position - position; float curDistance = diff.sqrMagnitude; if (curDistance < distance) { closest = go; distance = curDistance; } } if (recupgeste == "ga_circle_01" && recupgestescore > 0.60 || Input.GetKeyDown(KeyCode.Space)) { transform.position = Vector3.MoveTowards(transform.position, closest.transform.position, 100); } return closest; //THE PROBLEM //For each foe I have I hit them once (FoeHealth is the script (In start: FoeHealth = Foe.GetComponent();)and currentHealth the life variable in the script). foreach (GameObject go in Foes) { if (FoeHealth.currentHealth > 0 /*attackphas*/) { Debug.Log("TOOOK"); // ... damage the player. FoeHealth.TakeDamage(attackDamage); } } } Thanks in advance ^^

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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