Hi guys, long story short I’m looking to find a way to count targets as they appear on the screen. If I have one already in the scene I have no issues, it counts. But since I’m using a spawn script it won’t count the clones, any ideas? PS: I’m still new to scripting, this was created using the BurgZerg tutorials, Cheers guys!
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerTargets : MonoBehaviour {
public List<Transform> targets;
private Transform selectedTarget;
private GameObject target;
void Start () {
targets = new List<Transform> ();
AddAllEnemies ();
}
// Update is called once per frame
void Update ()
{
}
void OnGUI() {
GUI.Label (new Rect (10, 70, 1000, 20), "Enemies: " + targets.ToString ());
}
public void AddAllEnemies ()
{
targets.Clear ();
GameObject[] go = GameObject.FindGameObjectsWithTag ("enemy");
foreach (GameObject enemy in go)
AddTarget (enemy.transform);
}
public void AddTarget (Transform enemy)
{
targets.Add (enemy);
}
}