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

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: NGUI: HUD Text
« Reply #165 on: December 29, 2013, 07:02:07 AM »
It doesn't do raycasting. If you want it hidden, I suggest you perform a raycast periodically (toward the camera) and if something is hit, hide the HUD element.

I'm pretty new with the ray casting concept, any chance you have a short smaller tutorial of how you would accomplish something like this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #166 on: December 29, 2013, 06:52:30 PM »
Look into the Physics.Raycast in Unity documentation. It has an example on how to use it.
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

pjrm1470

  • Guest
Re: NGUI: HUD Text
« Reply #167 on: December 31, 2013, 11:02:16 AM »
I just bought it, and i'm having trouble trying to import only this package! I'm receiving this erro:
Quote
Error while importing package: Couldn't decompress package
UnityEditor.AssetStoreContext:OpenPackage(String, String)

any idea on how to fix it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #168 on: December 31, 2013, 11:42:05 AM »
I don't think I've ever seen that error. Looks like something in Unity. I suggest trying to restart it, and making sure that your Unity version is up to date.

pjrm1470

  • Guest
Re: NGUI: HUD Text
« Reply #169 on: December 31, 2013, 12:41:00 PM »
I don't think I've ever seen that error. Looks like something in Unity. I suggest trying to restart it, and making sure that your Unity version is up to date.
I did.
NGUI: Next-Gen UI kit install just fine. but this package, don't.
I'm thinking on reinstall unity3d.

==edit==
My Bad. after the 5th re-download, it work.
thanks!

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: NGUI: HUD Text
« Reply #170 on: January 09, 2014, 02:18:40 AM »
I think I am close.. but.  The text that shows up in the HUD Text is just huge.  I have 1.9 of HudText, and the 3.0.8 (latest download as of today).

I basically have a script that creates the Enemy Hud object from a prefab, and adds it to the Enemy HUD UI Root (Screen shots attached of the prefab contents.  The problem I have is that the text is just too big, and the UIFollow does follow the cube in the scene, but it is sluggish in its following.

The cube's HUD object (also included via a screen shot) basically includes the HUDTextTest.cs script that locates the cameras and connects up to the various objects after creating the prefab and adding it to the node in the UI tree.  They it starts a background coroutine to just pump a text message into the HudText object, and tweaks the value of the vital bar.  (FWIW, I get the cameras this way because when I add the oculus rift to what I am doing, I end up with extra cameras and was having a great deal of difficulty making sure I capture the correct one.  This script has not been optimized to pool the HUD objects and cache the retrieved cameras.

Everything else appears to work, any ideas what's wrong with the text size?

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: NGUI: HUD Text
« Reply #171 on: January 09, 2014, 02:43:07 AM »
OK, I hate it when that happens... As it turns out the Enemy HUD UI Root object had a size of 240x240x240; Interesting since it was a created as an empty game object and then dragged onto the UIRoot.

The next question I have is should the Enemy HUD UI Root object be a panel, or should it just be a GameObject, I know the examples showed the you had multiple panels in the scenes, but without the panel it appears to work... what is the benefit of an additional panel?  I do have a Player HUD displayed in the game as well as these dynamic ones.

Thanks for taking a look, if nothing else, maybe someone will find the example and the post helpful.  :)

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: NGUI: HUD Text
« Reply #172 on: January 09, 2014, 03:40:31 AM »
Using the code above, I am unable to turn off the display of the vital bar.

I have tried setactive(false) and NGUITools.SetActive(gameobject,false) on the Gameobject "Health Vital Bar".

Even disabling it in the prefab has it displayed when it is instantiated, although oddly enough the label inside where the Percentage would be shown is not affected (ie, it is not shown).

How in the world do you turn this off?  I have had the same problem on several other objects as well where they do not "obey" and cannot be disabled.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #173 on: January 09, 2014, 07:34:21 PM »
You need to use NGUITools.AddChild(parent, prefab) to create children under your UI hierarchy. You can't create objects in the middle of nowhere and then drag them onto the UIRoot because the scale is going to be way off. UIRoot is scaled by 2 / Screen height, which is usually a very small value. Not to mention that when you instantiate a UI element in the middle of nowhere, NGUI creates an extra panel -- which is bad for draw calls, but happens to be the only way to draw the widget(s) that are not under any other panel.

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: NGUI: HUD Text
« Reply #174 on: January 09, 2014, 08:12:35 PM »
  "You need to use NGUITools.AddChild(parent, prefab) to create children under your UI hierarchy"

The panel that was large was one I created inside the Unity Editor (not from code) :-).

It looks like the only remaining issue I have is the turning off of the sliders now. 

Alessaint

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 67
    • View Profile
Re: NGUI: HUD Text
« Reply #175 on: January 21, 2014, 04:38:10 AM »
I was wondering if HUD Text could be used to display text following an object with UIFollowTarget behaving in such way so that the text's position would be clamped within screen space (acting as pointer to see which direction off the screen the object lies). If not, could you please point me in direction where it would be best make the adjustments in the script?

ngb_yalta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NGUI: HUD Text
« Reply #176 on: February 07, 2014, 03:32:29 AM »
Got a strange flick bug, while calling HudText.Add() with Animation Event, some kind of flickering, any ideas?
Here is video:
Youtube link

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #177 on: February 08, 2014, 01:18:40 PM »
HUDText is meant to be used from Update() as there is a certain order to how it works. It seems the animation event is not a part of that update. You can achieve what you want by just using a coroutine like so:
  1. StartCoroutine(AddDamage(123f));
And the coroutine would be:
  1. IEnumerator AddDamage (float amount)
  2. {
  3.     yield return new WaitForSeconds(0f);
  4.     enemy.SendMessage("Damage", amount);
  5. }
I'll modify HUDText in the near future to make it possible to call it from outside of Update, but that trick should work for now.

ngb_yalta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: NGUI: HUD Text
« Reply #178 on: February 09, 2014, 05:27:25 AM »
I've tried use coroutine, but got the same issue

Caller script:
  1. void EventCall()
  2.         {
  3.                 StartCoroutine("DoDamage");
  4.         }
  5.        
  6.        
  7.         IEnumerator DoDamage()
  8.         {
  9.                 yield return new WaitForSeconds(0f);
  10.                 enemy.SendMessage("Damage", 15);
  11.         }
  12.  

Receiver:
  1. public void Damage (float damage)
  2.         {
  3.                 if(Health > 0)
  4.                 {
  5.                         Health -= damage;
  6.                         ht.Add(damage.ToString(), Color.red, 0);
  7.                 }
  8.         }
  9.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #179 on: February 09, 2014, 05:15:59 PM »
Hmm... I may have given the wrong function actually. It should be:
  1. yield return null;
...not WaitForSeconds.