Hey guys,
I am looking for someone to explain this a bit further for me. I am using a poolmanager and I pool the healthbars using the poolmanager. so here is how I spawn both the units and the healthbars...
IEnumerator WaveSpawning ()
{
//Debug.Log ("Waves Started");
for (int j = 0;j < waveCount; j++)
{
waveNumber = waveNumber + 1;
waveLabel.text = "Wave: " + waveNumber.ToString() + "/" + waveCount.ToString();
for (int i = 0; i < enemyCount; i++)
{
int prefabIndex = UnityEngine.Random.Range(0,3);
//Debug.Log("Unit spawned was" + prefabIndex);
_spawnedUnit = prefabList[prefabIndex];
Transform enemy = PoolManager.Pools ["Enemy"].Spawn (_spawnedUnit, spawnPoint.position, Quaternion.identity);
Transform healthbar = PoolManager.Pools ["HBPool"].Spawn (spawnedHB, spawnPoint.position, Quaternion.identity);
yield return new WaitForSeconds
(spawnWait
); }
yield return new WaitForSeconds
(waveWait
); }
if (waveNumber == waveCount)
{
wavesCompleted = true;
}
}
Now I spawn several units as you see the script and I need to assign each healthbar with each enemy unit and make them follow them. I have tried different approaches to get the UIFollowTarget but they dont work correctly so far. I tried to use the scripts on both Transforms but it gets messed up. Something like this on the enemy script Start() Function...
void Start()
{
EnemyMobScript.livesCost = this.lives;
enemyUnit = this.transform;
setHBPos = this.hbPos;
}
And this on the Update() function of the healthbar script...
void Update ()
{
enemyUnit = EnemyMobScript.setHBPos.transform;
UIFollowTarget.setTarget = enemyUnit;
}
So far without any luck, can any of you guys please give me a hand with this? just pointers on how to do the reference correctly as that is the one point im struggling with.
Thanks in advance. BTW ArenMook I know this functions are not supported by NGUI but I want to support the HUD NGUI functions for my game and working on learning.
Demigoth