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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
NGUI: HUD Text
« on: July 11, 2012, 01:31:33 PM »
What is it?

In the simplest form, it's like Scrolling Combat Text from World of Warcraft. Numbers pop up, fly up. Unlike SCT, the numbers get automatically added up (for up to one second), and positives and negatives get treated differently, so you can basically show DPS and HPS separately without any additional work on your end.

You can also use it to display text -- such as chat messages -- right above your character's heads. You can even tell messages to stay on the screen for X number of seconds before floating up and fading.

You can (of course) modify the curves for how the messages disappear. This very system is used in Windward.

Examples that come with the package

http://www.tasharen.com/hudtext/ex1/
http://www.tasharen.com/hudtext/ex2/

Video Tutorials

http://www.youtube.com/watch?v=diql3UP1KQM
http://www.youtube.com/watch?v=idVr8-jfdAI (adding unit health bars to go with HUDText)

Usage
  • Attach the HUDText script to a game object underneath your UIRoot and set the font it should use.
  • To make it follow an object drawn with another camera, attach UIFollowTarget to the same object and set its target.
  • From code, use HUDText's Add() function to add new floating text entries.
You can also tweak the splines on the HUDText script, changing the motion of the text as you see fit.

Example Usage
  1. HUDText hudText = GetComponent<HUDText>();
  2.  
  3. // This will show damage of 123 in red
  4. hudText.Add(-123f, Color.red, 0f);
  5.  
  6. // This will show "Hello World!" and make it stay on the screen for 1 second before moving
  7. hudText.Add("Hello World!", Color.white, 1f);
Have questions? Please ask and I'll improve the documentation accordingly.

Screenshot of it used in Windward

« Last Edit: August 03, 2013, 02:41:08 PM by ArenMook »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text Readme.txt
« Reply #1 on: July 12, 2012, 02:26:04 AM »

catacomber

  • Guest
Re: NGUI: HUD Text
« Reply #2 on: July 12, 2012, 07:20:55 PM »
Thank you so much for this! The minute I saw it, I scarfed it up. I'm sure I'll have questions but you've given me and many others great support so far with NGUI. This is just what I needed.  :  ) 

 :-*

catacomber

  • Guest
Re: NGUI: HUD Text
« Reply #3 on: July 14, 2012, 08:58:14 PM »
When I have both NGUI and Hud examples in the same project, I get these compiler errors:

Scripts named 'LookAtTarget.cs' exist in multiple locations (Assets/HUD Text/Examples/Scripts/LookAtTarget.cs). Please rename one of the scripts to a unique name.
Scripts named 'LookAtTarget.cs' exist in multiple locations (Assets/NGUI/Examples/Scripts/Other/LookAtTarget.cs). Please rename one of the scripts to a unique name.

If I rename one of the scripts, I get a new error message:

Assets/NGUI/Examples/Scripts/Other/LookAtTarget.cs(9,14): error CS0101: The namespace `global::' already contains a definition for `LookAtTarget'

What should I do? Thank you in advance. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #4 on: July 14, 2012, 10:07:46 PM »
Delete LookAtTarget from HUDText (or dont import it). I'll fix it in the next update -- it seems the metadata changed.

catacomber

  • Guest
Re: NGUI: HUD Text
« Reply #5 on: July 14, 2012, 10:08:55 PM »
Thank you!!!!   :)  I deleted it. No more errors. I know what it does and if I need to use it hopefully I can juggle things. It's useful for NPC's.  :  )  Especially if they're walking around!
« Last Edit: July 14, 2012, 10:13:46 PM by catacomber »

catacomber

  • Guest
Re: NGUI: HUD Text
« Reply #6 on: July 14, 2012, 10:22:34 PM »
Oops! Just reopened project and two new errors:

Assets/HUD Text/NGUI/Scripts/Editor/UIWidgetInspector.cs(16,19): error CS0433: The imported type `UIWidget' is defined multiple times
Assets/NGUI/Scripts/Editor/BMFontReader.cs(47,34): error CS0433: The imported type `BMFont' is defined multiple times

Not meaning to be difficult, just letting you know.  :  )  Patiently awaiting what to do. I'm really happy to have this.
« Last Edit: July 14, 2012, 10:26:15 PM by catacomber »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #7 on: July 14, 2012, 10:28:16 PM »
Post only in one place please. I get email notifications from every single post. No need to double them up.

http://www.tasharen.com/forum/index.php?topic=1013.0

oregon_tony

  • Guest
Re: NGUI: HUD Text
« Reply #8 on: September 08, 2012, 04:10:24 AM »
How to assign HUD Text to javascript object dynamically created in code?
I do this in my project to create a new game object via code in javascript:

var Zombie:GameObject;
Zombie=Instantiate(createThis[rndNr], transform.position, transform.rotation);

I was trying to do this to assign the script to my Zombie GO, but I get a compile error saying the type "HUDText" isn't found:

   var myHUD : HUDText;   //<< compile error
   Zombie.AddComponent("HUDText");
   myHUD = Zombie.GetComponent("HUDText");
   myHUD.Add(-123f, Color.red, 0f);

Thanks,
Tony

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #9 on: September 08, 2012, 03:05:33 PM »
HUDText scripts would need to go into the Plugins folder. Roughly the same place as NGUI when used with javascript.

nkls

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: NGUI: HUD Text
« Reply #10 on: September 25, 2012, 04:09:26 AM »
Hi.
Bought this extension a couple of days ago, and I really like it. It works great, but I have a question.
Im setting my UIroot by script, to make it support different aspect ratios. Im adding my hud-labels with a reference font, but when i add them by code (score.Add(1500f, Color.green, 0.75f) they dont get the correct scale in my scene. If i add a label with the create widget tool those labels are scaled correctly.
How do I solve this problem?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #11 on: September 25, 2012, 08:43:45 AM »
What do you set on the UIRoot by script?

nkls

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: NGUI: HUD Text
« Reply #12 on: September 25, 2012, 09:08:46 AM »
I have 3 atlases, SD,HD and SHD. I use my SHD when doing the layout, and my pixel size on that one is 0.5.
I set my Manual height on start by script.

I fixed the problem (temporarily?) by edit this line in the HUDtext script:
float size = font.size * Mathf.Clamp01((time - ent.time) * 4f);

If i divide font.size / 2 everything looks good again.. Is this the right way to go?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI: HUD Text
« Reply #13 on: September 25, 2012, 09:38:42 AM »
Multiply it by font.atlas.pixelSize instead.

nkls

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 29
    • View Profile
Re: NGUI: HUD Text
« Reply #14 on: September 25, 2012, 10:16:13 AM »
Great, thank you.