Author Topic: NGUI: HUD Text  (Read 164007 times)

invitado123

  • Guest
Re: NGUI: HUD Text
« Reply #90 on: March 01, 2013, 09:40:39 AM »
You never set the uiCamera property of UIFollowTarget, so it may be finding the wrong one. When you select the instantiated object, where does it appear to be?

The UI camera property is set in the prefab itself, when it gets instantiated it is set correctly.

The object is instantiated under the GUI Object which contains the UIRoot script. I've attached a screenshot of the Hierarchy and Inspector


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #91 on: March 01, 2013, 09:48:03 AM »
Some issues I see with your setup:
- I don't see a UIRoot or UIAnchor. Your hierarchy seems to not follow NGUI's default UI setup.
- Your instantiated object is not parented to the UI camera.
- I can't see the transform so I don't know what the values there like... however without a UIRoot I imagine they text ends up being huge. Zoom out.

invitado123

  • Guest
Re: NGUI: HUD Text
« Reply #92 on: March 01, 2013, 10:04:54 AM »
Some issues I see with your setup:
- I don't see a UIRoot or UIAnchor. Your hierarchy seems to not follow NGUI's default UI setup.
- Your instantiated object is not parented to the UI camera.
- I can't see the transform so I don't know what the values there like... however without a UIRoot I imagine they text ends up being huge. Zoom out.

The GUI Object is the UI object created by the UI setup, I just changed it's name but it does contain the UIRoot script

I tried parenting the object to the Camera under the GUI object to no avail, I also tried parenting to the Anchor object below the Camera object, still the same problem, I've attached another screenshot showing the transform values.

I also noticed that the labels created appear to be shown in the Scene view as tiny specks of white. I've attached a second screenshot of this. It may just be an artifact but that speck of white you see next to the selected object is another label the same as the one that is selected. I am unable to zoom to it as it just dissapears from view, it's just like a dot

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #93 on: March 01, 2013, 10:39:10 AM »
Tiny speck of white suggests that your label's size is tiny. Your transform's position is strange. -1414? I'm pretty sure that's off-screen. Are you absolutely 100% sure that your UI camera points to the right one? You mentioned it's set in the prefab... but that's impossible as the prefab can't reference objects that are not within this prefab... and your UI camera should not be in that prefab.

invitado123

  • Guest
Re: NGUI: HUD Text
« Reply #94 on: March 01, 2013, 11:44:58 AM »
To make sure I've added these lines to my code:

  1.                         GameObject nGUI = GameObject.Find("GUI");
  2.                         Transform camera = nGUI.transform.FindChild("Camera");
  3.                         Transform anchor = camera.FindChild("Anchor");
  4.                         GameObject scoreLabel = NGUITools.AddChild(anchor.gameObject, scoreLabelPrefab);
  5.                         UIFollowTarget follow = scoreLabel.GetComponent<UIFollowTarget>();
  6.                         follow.target = transform;
  7.                         follow.gameCamera = Camera.main;
  8.                         follow.uiCamera = camera.gameObject.GetComponent<Camera>();
  9.                         HUDText hudText = scoreLabel.GetComponent<HUDText>();
  10.                         hudText.Add(starValue, Color.red, 0.0f);
  11.  

This makes sure that the correct camera is set, attached is a screenshot of the higlighted gameobject upon selecting the UI Camera on one of the instanced labels.

I agree that speck suggests the label's size is tiny but increasing their scale doesn't appear to have any effect. Also moving the labels to positions 0,0,0 don't show them on screen

aidji

  • Guest
Re: NGUI: HUD Text
« Reply #95 on: April 06, 2013, 01:46:55 AM »
Is there a simple way to use UIlocalise script on the HUD texts clones?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #96 on: April 06, 2013, 01:04:56 PM »
@invitado: Is your anchor center-aligned? Is the GUI object the one with UIRoot? Is your game camera the only one tagged as "MainCamera"? What does your camera tool window look like?

@deldama: UILocalize doesn't work with HUDText. Instead you should Localization.Localize() the text before passing it to HUDText.

wangzy_88

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 33
    • View Profile
Re: NGUI: HUD Text
« Reply #97 on: April 22, 2013, 03:35:47 AM »
How to make a health bar follow with prefab objects?Some of the same objects.

aidji

  • Guest
Re: NGUI: HUD Text
« Reply #98 on: April 28, 2013, 06:19:36 AM »
Hi, i have a problem with Hud Text Point (scripts UIPANEL, HUDROOT, HUDTEXTPOINT):

in the inspector i setup the public Target to : A gameobject
when i run the game i change target to B or C gameobject and pop the hud text but it appear only to target A gameobject, i have checked when the game run the target in the inspector is changed, but the HUD text i pop only keep the value i give before running the game. am i missing something?

after some time i found a way i need to use i cant change the target frpm HUDtextpoint because the cloned HUD TEXT will not update the target, am i Right? so i need one HUD TEXT POINT script for each target?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #99 on: April 28, 2013, 04:14:23 PM »
What is HUD Text Point?

aidji

  • Guest
Re: NGUI: HUD Text
« Reply #100 on: May 01, 2013, 03:03:41 AM »
Hi, here is the script

  1. using UnityEngine;
  2. [AddComponentMenu("NGUI/Examples/Collider - Display Text")]
  3. public class HudTextPoint : MonoBehaviour
  4. {
  5.  
  6.         public GameObject prefab;
  7.         public Transform target;
  8.         public string Text;
  9.         public Color TxtColor;
  10.         public float timer;
  11.  
  12.         HUDText mText = null;
  13.  
  14.         void Start ()
  15.         {
  16.        
  17.                 if (HUDRoot.go == null)
  18.                 {
  19.                         GameObject.Destroy(this);
  20.                         return;
  21.                 }
  22.  
  23.                 GameObject child = NGUITools.AddChild(HUDRoot.go, prefab);
  24.                 mText = child.GetComponentInChildren<HUDText>();
  25.  
  26.                 // Make the UI follow the target
  27.                 child.AddComponent<UIFollowTarget>().target = target;
  28.         }
  29.  
  30.        
  31.         public void PopText (){
  32.                
  33.                 mText.Add(Text, TxtColor, timer);
  34.                
  35.         }
  36. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #101 on: May 01, 2013, 03:25:37 AM »
You'd need one of these on each object that should use HUDText. For example if you have 2 players, each one needs this script to have text appear over their heads.

redhawk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: NGUI: HUD Text
« Reply #102 on: May 15, 2013, 04:27:21 PM »
One of the most common questions I get is how to add more than just text to the HUD UIs created with HUDText.

Well... here's a video!

http://www.youtube.com/watch?v=idVr8-jfdAI

Oh please add this video Link to the Unity Store, your Unity Forums Post (at the top in your intro) and on this Forum board at the top in your Intro.  Also please add a description above the Links (like HUDText Tutorial, HUDText Health Bars). I just found this after reading through this entire post when this is all I was looking for :)

Darkness

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 90
    • View Profile
Re: NGUI: HUD Text
« Reply #103 on: August 03, 2013, 05:08:04 AM »
I'm not sure where to put this, but since this is the HUD Text thread, I figured I'd start here.

I want to be able to adjust the scale curve in code.  How do I go about doing that?  I tried hudText.scaleCurve().AddKey, but that doesn't work.  Is there any way I can adjust this without doing it manually?  I'd be easier to simply do it in code so that all NPCs have the correct crit damage effect.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #104 on: August 03, 2013, 02:40:15 PM »
Remove the () from scaleCurve.