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

rei

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: NGUI: HUD Text
« Reply #210 on: July 27, 2014, 10:48:11 AM »
Hello,
I created a system of enemies spawn.
I already have a prefab enemy with his life bar, how can I associate a life bar each instance of enemy.
Do you have a sample script?

sorry for my english, google translation

thank you for your help

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #211 on: July 27, 2014, 11:35:52 PM »
Create a custom MonoBehaviour attached to your enemy:
  1. public class YourCustomMonoBehaviour : MonoBehaviour
  2. {
  3.     public HUDText hud;
  4. }
When you instantiate your UI object, assign the "hud" reference:
  1. GameObject go = NGUITools.AddChild(uiRootObject, lifebarPrefab);
  2. go.GetComponent<UIFollowTarget>().target = your3DEnemy;
  3. your3DEnemy.GetComponent<YourCustomMonoBehaviour>().hud = go.GetComponent<HUDText>();
You can now use the HUDText element from your 3D enemy just by doing your3DEnemy.GetComponent<YourCustomMonoBehaviour>().hud.

rei

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: NGUI: HUD Text
« Reply #212 on: August 05, 2014, 11:58:01 AM »
Thank you for help ArenMook  :)

I still have trouble understanding the operation.
But I advance.

ArtemKoval

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: NGUI: HUD Text
« Reply #213 on: August 10, 2014, 11:19:36 AM »
Hi!

Do you have any idea why healthbar jumping is happening? Video is here - https://dl.dropboxusercontent.com/u/19764309/Caelum%202014-07-30%2022-19-36-91.avi

Thanks, Artem.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #214 on: August 10, 2014, 06:28:50 PM »
It's not jumping, it's merely snapping to pixels. Your ships don't, but GUI does. If you don't want it to snap, look at the UIFollowTarget script. It does the snapping inside so just change it.

ArtemKoval

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: NGUI: HUD Text
« Reply #215 on: August 12, 2014, 10:22:04 AM »
Yep, that helped. Thanks. It's still has slight jitter, but I guess it has something to do with really small delta position per frame (somewhat of 0.0001 of unit).

Benzino07

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 24
    • View Profile
Re: NGUI: HUD Text
« Reply #216 on: August 20, 2014, 04:58:53 AM »
Hi, first up great work on NGUI and this extension, they are fantastic.

I have 2 questions:

1) Would using HUDText/NGUI be the best approach for displaying text, icons and progress bars above buildings in a game world? An example of this would be Clash of Clans:



2) Is there any way to get UILabels/UISprites to scale if the main camera (not the UICamera) is zoomed in or out (by adjusting orthographic size)? Currently they maintain the same size regardless of zoom level and you can see their position change as you zoom in. The sprites and labels is are up to follow a gameObject in the game world using UIFollowTarget.

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #217 on: August 20, 2014, 06:06:39 PM »
1. If you want a 2D UI overlay on top of a 3D or isometric game world, then yes.

2. If you want them to scale with the camera zoom level, then I wouldn't use a UIFollowTarget in this case. I'd make my HUDText / HUD elements be children of the 3D game object. This way they would naturally get bigger as you zoom closer, as they would be in your world rather in your UI.

PatrickHC

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: NGUI: HUD Text
« Reply #218 on: August 21, 2014, 09:53:59 AM »
HI Team,
I am trying to following the tutorial https://www.youtube.com/watch?v=diql3UP1KQM
But any chances to lemme know methods to modify the generated number (font size/ position / content)
Many thx!

Patrick

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #219 on: August 22, 2014, 04:48:18 AM »
To modify those properties, select the game object that has the HUDText script attached and modify them in inspector.

sgolby

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: NGUI: HUD Text
« Reply #220 on: November 21, 2014, 11:19:15 AM »
When using an Outline effect on a font I am finding the HUD Text "fades to black" rather than fades transparent.
Turning off the Outline Effect fixes it as can be seen in the screenshot.
Is this a known issue ?

The bad news is my HUD Text is probably quite old, the file date is 10/28/2013 (I can't seem to find a version in the files) the reason being I'm stuck on NGUI Pro v2.7.0 until I have time to do a major upgrade. (game was supposed to be released late 2013 right when 3.0 beta came out, so I decided not to change just before release, and the release got majorly delayed)

So... if "Just Upgrade" is the answer, will the current version of HUD Text on the Asset Store download work with NGUI v2.7.0 ?   or can I get the last version of HUD Text that matches NGUI Pro v2.7.0 somehow ?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #221 on: November 21, 2014, 09:19:07 PM »
This is due to how outline is done. TO draw an outline, text is drawn multiple times. First in black, then in your proper color (in your case -- pink). When you fade a label, it does the same thing, just with a semi-transparent alpha. In your alpha = 1.0 case, you only see black on the edges. Pink colors the center fully. However when you fade something, the blackness can be seen through it.

There is no way around it other than creating this font effect in photoshop instead of using the inspector-chosen effect.

sgolby

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: NGUI: HUD Text
« Reply #222 on: December 03, 2014, 11:17:51 AM »
Thanks for the explanation, I used the Curve stuff to more quickly adjust the Alpha channel towards the tail end so it fades very fast now in the last 0.5s but stays at 100% for most of the float up, a lot less noticeable.

SkaiCloud

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: NGUI: HUD Text
« Reply #223 on: December 17, 2014, 01:32:16 AM »
ArenMook,

I know HudText hasn't been updated for awhile but I still like it. I'm trying to add random value to the offset curve but it requires me to edit the code but I'm not as good as you cause I tried to add some curve and it either gives me errors or does things that I expected to do but didn't do. In future updates (which I hope soon) can you add random side curve and random offset curve? It would be nice to allow us to adjust which way the text will fly, bounce, zoom out etc. Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #224 on: December 17, 2014, 03:56:15 PM »
Why do that? Assuming you are trying to do something like add hud text above the character's head, you should be making UIFollowTarget follow a game object that's above the player's head, not the player itself. I'm not suite sure what you mean by "random offset curve". What are you trying to randomize?