I've tried this:
public GameObject[] enemies;
public Transform curTarget;
public float[] enemyDists;
public float curEnemyDist;
public int count = 1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
enemies = GameObject.FindGameObjectsWithTag ("Player");
foreach (GameObject enemy in enemies) {
enemyDists[count - 1] = Vector3.Distance (transform.position, enemy.transform.position);
count +=1;
}
count = 1;
foreach (float dist in enemyDists) {
if(dist < curEnemyDist) {
Debug.Log("HELLO");
}
}
//This is constantly update the targetw ith the new/current target in this script..
GetComponent ().target = curTarget;
curEnemyDist = Vector3.Distance (transform.position, curTarget.transform.position);
foreach (float dist in enemyDists) {
}
}
But it ain't working. I need to grab the transform of the gameobject in the array and get the distance between that and this.transform. How can I do that?
↧