Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NGUI: HUD Text

Discussion in 'Assets and Asset Store' started by ArenMook, Jul 12, 2012.

  1. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I'm pretty sure this utility went through no less than 4 different names while I was working on Windward, but the Asset Store now knows it as NGUI: HUD Text.

    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.

    Using the system is trivial. Attach HUDText to some object in your NGUI's UI hierarchy (you will want one of these per unit). Call HUDText's Add(content, color, duration), where 'content' is either a string or a float, and 'duration' is how long it should stay on the screen before starting to fade.

    Ideally you will likely want to create this once and save it as a prefab, then instantiate it dynamically for each unit. The script that can be used to make this 2D UI follow a 3D target is called UIFollowTarget, and is included with the package. Don't forget to destroy the HUDText object if your unit dies though!

    Examples that come with the package:
    http://www.tasharen.com/hudtext/ex1/
    http://www.tasharen.com/hudtext/ex2/

    Video Tutorial
    http://www.youtube.com/watch?v=diql3UP1KQM

    Support thread: http://www.tasharen.com/forum/index.php?topic=997.0

    This is what it looks like in Windward, but I suggest checking out the examples or Windward itself to see it in action.

     
    Last edited: Jul 17, 2012
  2. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Just purchased. Though it seems to have broken a bunch of references but I'm sure that's because I'm running a very old version of NGUI .. time to upgrade. :)
     
  3. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440
    Do you have one where the label 'sticks' there? or one that is able to put a picture ontop of an object?
     
  4. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Label "sticking" there, as in permanently? Ie: player name? You can do that by simply adding a regular label, then attaching UIFollowTarget script to it and making it follow something in your world.
     
  5. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440
    can you make a tutorial for that?
    for some reason, if you copy paste the stuff from your NGUI-HUD text demo to a angry robots project, it does not work.
    even when you try to click on a robot, nothing happens.

    Of course, It could be me - it some parameter I forgot to add when copying over.
     
  6. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Copy/pasting doesn't copy over the metadata. You need to export it as a package and import it in the other project (or just import this package in its entirety).
     
  7. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Is using UIRoot essential for the use of HUD Text? I didn't use UIRoot in my GUI and if I add it now, it changes everything in the GUI completely (compresses everything to be at a single point in the centre of the screen). If it can be used without UIRoot, where should I attach the object that has the HUDText script?
     
  8. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Nope, UIRoot it's not needed, but you can still add it and uncheck the "automatic" checkbox and set the size to "1", which will have the same effect as not having UIRoot. Why do you ask? HUDText doesn't use UIRoot directly.
     
  9. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    In the HUDText readme file it says to add UIText script to an object attached under the UIRoot.
     
  10. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Implies just add it somewhere underneath your UI hierarchy like you would add a label.
     
  11. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
  12. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    I got this working yesterday and it is absolutely awesome. It really added that final touch to my game GUI as it gives the opportunity to add a brief explanation of otherwise confusing events. Really great asset ... thanks for releasing it.
     
    Last edited: Jul 17, 2012
  13. Yippie

    Yippie

    Joined:
    May 4, 2009
    Posts:
    227
    Awesome, i'm gonna pick it for my next game :D
     
  14. Kergal

    Kergal

    Joined:
    May 10, 2012
    Posts:
    14
    really like the package , however I have a problem. :)
    http://i50.tinypic.com/34eq35f.png <- There it is :)
    all the texts are mirror inverted and i have no idea how to fix that.
    In the inspector you can see (selected) the tower -> its HUDTEXT (child) and the attached scripts.
    My camera is the main camera i use for the game.

    Any ideas?
     
  15. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    My guess is you forgot to add HUDRoot to your UI hierarchy somewhere, because judging from that screenshot your HUDText elements are getting created in the middle of nowhere :p
     
  16. Deleted User

    Deleted User

    Guest

    I just purchased this and it was pretty easy to get up and running. Two questions:
    1. Maybe I missed it but it looks like my game has a warning at the top saying I am using the free version of NGUI. It might have seemed obvious but I assumed since this came with a compiled version of NGUI I could just purchase this extension, is that incorrect?
    2. I am having a lot of trouble getting a custom font to work. I can add the font material but even after repositioning the pixel rectangle all I seem to get is gibberish. Do you have any tutorials for using a custom font? I am using the free joystix font from the asset store.

    Great package so far.
    Thanks!
     
  17. jaybones_old

    jaybones_old

    Joined:
    Mar 31, 2010
    Posts:
    21
    I'm interested in this package, i wanted to know if this works with MGUI free version.
    thanks,
    jay
     
  18. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    @ryandb2: The package comes with the distributable version of NGUI. If you already have NGUI, don't import the NGUI folder from the package. For tutorials on how to add new fonts to NGUI, check the NGUI tutorials found here: http://www.tasharen.com/?page_id=197

    @jaybones: Yup. You will want to replace the distributable version with the free version so that you'll be able to modify everything correctly. The steps are the same as upgrading NGUI: new scene, delete NGUI folder, import from another NGUI package.
     
  19. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    So would I have problems using this in a project that already has NGUI in it?
     
  20. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Nope. Just don't import the NGUI folder from the HUDText package.
     
  21. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Thanks!
     
  22. Enrique SubZero

    Enrique SubZero

    Joined:
    Aug 25, 2012
    Posts:
    2
    I tried the example from the youtube video. It works, but I get the following error:

    Expected to have 'target' set to a valid transform
    UnityEngine.Debug:LogError(Object, Object)
    UIFollowTarget:Start() (at Assets/HUD Text/Scripts/UIFollowTarget.cs:52)

    I did set the target from the UIFollowTarget script so I'm not sure why this is happening.
     
  23. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    The only way that code gets triggered is if you didn't set the "target" variable. Double-check the script in question.
     
  24. Enrique SubZero

    Enrique SubZero

    Joined:
    Aug 25, 2012
    Posts:
    2
    Oops, there was another instance of the UIFollowTarget script attached to the label (must have gone wrong with dragging).
    This explains why it worked anyway. ;-)
    Works without errors now.
     
  25. VGiu

    VGiu

    Joined:
    Sep 4, 2012
    Posts:
    1
    Does the UIFollowTarget work with other elements as well or just labels?
    I'm thinking about using it for health bars above characters in a game, would that work?
     
  26. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Sure does. You can use it to have a game object in the UI hierarchy follow an object in the game, and you can add any children you want to it. In Windward I use it for health bars as well.
     
  27. rosevelt

    rosevelt

    Joined:
    Oct 23, 2012
    Posts:
    47
    Hello,

    Is there a way to show(for instance) a Critical Hit, by first popping up a bigger font size, then shrinking it to a normal size?
    such as in many other SCT systems found in games these days.

    Thanks
     
  28. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    I would suggest using two HUDTexts for that -- one for regular hits, and another for crits. You can change the animation on the crit one to appear and grow, then shrink down, achieving exactly that.
     
  29. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    I tried unchecking HUD Text/NGUI and it just slams my console with errors after import. Does this work with Unity4? If so please provide some install steps (video or pictures please) as I've done as said "simply uncheck NGUI folder" and it does not work. Note I do have the commercial version of NGUI bought and imported from asset store, which works and is where the errors come from after import.
     
  30. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Yeah it does. I suggest the following steps:

    1. Create a new scene in your project (don't save it)
    2. Import HUDText
    3. Delete the NGUI folder
    4. Import the full version of NGUI.
     
  31. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    I see, what If I already have NGUI imported? Just delete and re-import? Thank you for the steps!
     
  32. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    It's more iffy if you do it in a different order. You should be safe to delete it and follow the steps above though.
     
  33. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    Ok, thank you!
     
  34. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    I attached UIFollowTarget component but the hud text is always put the center of the screen not at the target object's position.

    Any ideas?

    - Kim
     
  35. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Did you set its target to be your game object? Is it on the correct game object layer? UIFollowTarget should be on the UI layer, and your game object that you want it to follow needs to be on a different layer. Your cameras need to be set up correctly as well -- UI camera shouldn't see anything except the UI layer, and the game camera shouldn't see the UI layer.
     
  36. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Fixed.

    I have several cameras and the proper camera was not assigned to UIFollowTarget.

    That was the problem.


    Thank you for the proceeding.

    -Kim
     
  37. daisySa

    daisySa

    Joined:
    Dec 29, 2011
    Posts:
    341
    I want to display text permanently above a character. I've defined a UILabel under a 2D UIRoot, entered some text and attached UIFollowTarget. I've set Target to be a new gameobject which I've placed just above the head of the character.

    However, nothing is displayed and there are no console messages. UIFollowTarget is on the UI camera layer, and the target is on the Main Camera layer. The cameras exclude each other.

    Any help much appreciated!
     
  38. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    It sounds like you've covered all the basics there... just one question: main camera layer? What's that? Do you mean it's on the Default layer that's seen by the main camera but not by the UI camera? If nothing else, I suggest adding some Debug.Log statements to the UIFollowTarget script to see what cameras it chooses, and what values it calculates.
     
  39. daisySa

    daisySa

    Joined:
    Dec 29, 2011
    Posts:
    341
    Thanks, that was very helpful. UIFollowTarget was choosing a camera which is dynamically created by a minimap plugin I'm using. If I deactivate the map plugin, the correct cameras are chosen and the text is visible above the target's head. I'll look deeper into the map code to resolve it.

    However, I'm still having a couple of issues:

    1. If I turn my character (not the target) around 180 degrees, the target text is displayed there on the horizon as well, even though I have DisableIfInvisible checked.

    2. The target text appears in the centre of the screen when I first start the scene. It moves to its correct position above the target as soon as my character faces it. Strangely, this does not happen if I uncheck "DisableIfInvisible".

    Any ideas as to what I'm doing wrong? The log statements in UIFollowText show that mGame is using the default camera, and mUICamera is set to the camera in the NGUI UI which has the label attached.
     
    Last edited: Jan 12, 2013
  40. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    You need to use NGUITools.AddChild to instantiate objects, and you should set up your hierarchy like so:

    HUD GameObject (UIFollowTarget on it)
    - HUDText GameObject (with HUDText on it)
    - UILabel GameObject for unit name (if you need it)

    Instantiate the HUD GameObject (which also should be a prefab).
     
  41. daisySa

    daisySa

    Joined:
    Dec 29, 2011
    Posts:
    341
    Thanks, but I just can't work out what I'm doing wrong. Does it have to be done in code? The DPS text (HUD Text) works fine - it's worked from day one. My problem is with just simply attaching some floating text with UIFollowText - it displays the text above the character, but if you turn the camera 180 degrees, the text reappears.

    My hierarchy is UI Root (2D) > UI Camera > Anchor Bottom > HUD > Panel > Label, where "label" is just a UILabel with UIFollowTarget attached. Target (in UIFollowTarget) is pointing to a transform under the target character's root.

    My health bar does the same thing. It decrements nicely when the character is attacked, it's all working fine…except it also appears 180 degrees from the target (i.e. with the camera's back facing the target).

    Is there anything obviously wrong there? I'm sure it's something really basic but I'm too new to most of this to be able to see it.
     
  42. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Ping me on skype (arenmook) with your invoice # and I will hook you up with the latest version that I'm working with that I haven't released yet. If it doesn't fix the issue outright, I will be able to at least tell you what you did wrong easier :p
     
  43. WillBellJr

    WillBellJr

    Joined:
    Apr 10, 2009
    Posts:
    394
    I just had to pop in to complement you, ArenMook - I have to say your products really add some great capabilities to Unity and the quality of your software AND support is outstanding!

    Cheers to you!

    I'm not sure if I need this for my game (which is also using NGUI) but I may pick this up anyway because it seems like a great additional feature to have for NGUI.


    If anything, I would see if I could place this text over my cockpit computer screens models to make it appear there's text scrolling up on the displays etc.

    If not, then still - this looks to be a great product.

    -Will
     
  44. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Thanks!

    HUDText is mainly for 2D text, but you can certainly set it up to scroll even in 3D space (just don't use the UIFollowTarget script and place your HUDText as a part of your 3D world). That said, I am not sure if it would be the best approach to what you'd like to do. Scrolling text on a cockpit object would be easier to accomplish by adjusting UVs of a normal texture.
     
  45. daisySa

    daisySa

    Joined:
    Dec 29, 2011
    Posts:
    341
    Many thanks for helping resolve my issue earlier today via Skype. All working pefectly now - so good!
     
  46. WillBellJr

    WillBellJr

    Joined:
    Apr 10, 2009
    Posts:
    394
    Agreed, but I figured if it made the task of throwing text onto the display a bit easier AND it looked great, hey why not - I'd have to of course try it all out first!

    Once again, I appreciate your great products!


    -Will
     
  47. cpasjuste

    cpasjuste

    Joined:
    Apr 2, 2012
    Posts:
    154
    Hi,

    First thanks, the effect is great and time winner :)

    I do encounter a problem on Android: the UIFollowTarget script is not working, the text is always drawn at the center of the screen. It's working fine in the editor tough! I was not able to find the time to search for the problem (but i do not see any problem in debug output) and hope you'll be able to take a look to confirm and fix that :D

    Thanks,
    David.

    Edit: i did a little more research and found that all the position are correct on android including the new local position ( mTrans.localPosition ) so i really don't understand what's happening, all the HUDText position are not updated on screen :x

    Edit2: in fact it's only working in the editor game mode, if i build the exe for windows the HUDText's are drawn at the center of the screen.

    Edit3: my problem was an UIAnchor script attached to my HUDText gameObject :x
    Sorry for the buz :)
     
    Last edited: Jan 16, 2013
  48. sameer-mirza

    sameer-mirza

    Joined:
    Nov 14, 2011
    Posts:
    36
    Hi Aren,

    I'm trying to use HUD Text with multiple cameras (Vertically split screen). The HUD objects don't seem to work correctly (they work fine when I switch to single screen mode). I know I've to look at the Update function of UIFollowTarget and do something there, just wanted to hear your thoughts about it.

    Regards,
    Sameer.
     
  49. ArenMook

    ArenMook

    Joined:
    Oct 20, 2010
    Posts:
    1,902
    Multiple cameras likely mean they draw the same stuff, so the UIFollowTarget script doesn't know which script to use for calculations.

    Add me on skype (arenmook), let me know your invoice #, and I will send you a version of the script where you will be able to explicitly specify the cameras.
     
  50. sameer-mirza

    sameer-mirza

    Joined:
    Nov 14, 2011
    Posts:
    36
    Thanks for the tip, Aren, I got it to work eventually.