Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: will_brett on January 18, 2014, 03:52:22 PM

Title: HUD Text issue
Post by: will_brett on January 18, 2014, 03:52:22 PM
Hi everyone,

Just purchased HUD Text and its a pretty neat little package. However I think Im using it wrong.

I create a UI and under the panel create a sprite and attach the UIfollowTarget script. This works perfectly but I am attaching i am following an enemy that when I destroy posts out a load of errors saying the script is looking for the target but it is not there.

Should I create the UI under the enemy object itself? This would mean having multiple UI's and the enemies are prefabs that keep re-spawning.

Sorry if this is obvious but could do with some guidance.

Thanks
Title: Re: HUD Text issue
Post by: will_brett on January 18, 2014, 05:07:15 PM
Thinking about it I think I need to make a script the instantiates the HUDText for each enemy under the UIRoot. Not to sure how I would go about this
Title: Re: HUD Text issue
Post by: will_brett on January 18, 2014, 05:46:37 PM
This didnt work but is it on the right track?

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class InstantiateHUDText : MonoBehaviour
  5. {
  6.  
  7.         public GameObject hudText;
  8.         public GameObject parent;
  9.  
  10.         // Use this for initialization
  11.  
  12.         void Start ()
  13.         {
  14.                 hudText = NGUITools.AddChild(parent);
  15.  
  16.         }
  17.        
  18.         // Update is called once per frame
  19.         void Update ()
  20.         {
  21.  
  22.         }
  23. }
  24.  
Title: Re: HUD Text issue
Post by: will_brett on January 18, 2014, 06:27:25 PM
Got it to instantiate the correct prefab in the correct place using:

  1. hudText = NGUITools.AddChild(parent, hudText);

However the "UI Follow Target" script has lost the gameObject it is meant to follow and both cameras.

So I guess my new question is how do I get the the script to keep the target objects so that when it is instantiated it will know exactly which target to follow bearing in mind I will be instantiating multiple enemies all with the same tag.
Title: Re: HUD Text issue
Post by: ArenMook on January 18, 2014, 09:58:43 PM
Prefabs can't reference objects and scripts that are not a part of the prefab. It's a Unity limitation that makes perfect sense if you think about it. You will need to set those references after instantiation.
Title: Re: HUD Text issue
Post by: Rollingdjs on March 20, 2014, 01:21:04 AM
did you get this working? I have been trying to set the hudtext properly, but it never follows the target.