Author Topic: Help with healthbars and using PoolManager  (Read 1662 times)

Demigoth

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 18
    • View Profile
Help with healthbars and using PoolManager
« on: May 27, 2014, 09:41:19 PM »
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...

  1. IEnumerator WaveSpawning ()
  2.         {
  3.                 //Debug.Log ("Waves Started");
  4.                 for (int j = 0;j < waveCount; j++)
  5.                 {
  6.                         waveNumber = waveNumber + 1;
  7.                         waveLabel.text = "Wave: " + waveNumber.ToString() + "/" + waveCount.ToString();
  8.                         for (int i = 0; i < enemyCount; i++)
  9.                         {
  10.                                 int prefabIndex = UnityEngine.Random.Range(0,3);
  11.                                 //Debug.Log("Unit spawned was" + prefabIndex);
  12.                                 _spawnedUnit = prefabList[prefabIndex];
  13.                                 Transform enemy = PoolManager.Pools ["Enemy"].Spawn (_spawnedUnit, spawnPoint.position, Quaternion.identity);
  14.                                 Transform healthbar = PoolManager.Pools ["HBPool"].Spawn (spawnedHB, spawnPoint.position, Quaternion.identity);
  15.  
  16.                                 yield return new WaitForSeconds (spawnWait);
  17.                         }
  18.                         yield return new WaitForSeconds (waveWait);
  19.                 }
  20.                 if (waveNumber == waveCount)
  21.                 {
  22.                         wavesCompleted = true;
  23.                 }
  24.         }
  25.  

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...

  1. void Start()
  2.         {
  3.                 EnemyMobScript.livesCost = this.lives;
  4.                 enemyUnit = this.transform;
  5.                 setHBPos = this.hbPos;
  6.         }
  7.  

And this on the Update() function of the healthbar script...

  1. void Update ()
  2.         {
  3.                 enemyUnit = EnemyMobScript.setHBPos.transform;
  4.                 UIFollowTarget.setTarget = enemyUnit;
  5.         }
  6.  

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