Author Topic: HUD Text issue  (Read 4480 times)

will_brett

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 40
    • View Profile
HUD Text issue
« 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

will_brett

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 40
    • View Profile
Re: HUD Text issue
« Reply #1 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

will_brett

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 40
    • View Profile
Re: HUD Text issue
« Reply #2 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.  

will_brett

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 40
    • View Profile
Re: HUD Text issue
« Reply #3 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text issue
« Reply #4 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.

Rollingdjs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: HUD Text issue
« Reply #5 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.