Author Topic: Attach label to standard game object?  (Read 5706 times)

BlueSin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 17
    • View Profile
Attach label to standard game object?
« on: October 30, 2015, 01:03:00 PM »
I am currently creating a 2D side scrolling sci-fi shmup and designing the missions for it.  In some of these missions, there are friendly units that I want to designate with a label above them in green text [FRIENDLY], because if the player kills them they suffer a score penalty at the end of the round.  What would be the best way to accomplish this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Attach label to standard game object?
« Reply #1 on: October 31, 2015, 02:12:05 AM »
Any widget can be anchored to something else, including a 3D object. You can also use the UIFollowTarget script from the HUDText package if you have it.

BlueSin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Attach label to standard game object?
« Reply #2 on: October 31, 2015, 05:00:41 AM »
Hmm but the second I do that it creates a new UI Root and moves the game object in there, including the parent which is a spaceship flying in space lol.  Causes a big problem since I already have a UI Root and it is creating a new one by default it would seem.  Is there another option besides the HUDText package?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Attach label to standard game object?
« Reply #3 on: October 31, 2015, 09:23:28 AM »
Your UI should be separate from the game models, even if they're 2D. One UIRoot is normal and is expected. The widget underneath it can still be anchored to something not a part of your UI. Why are you getting a second one? What is it you're actually doing? All you need is:

1. ALT+SHIFT+L to add a label.
2. Set it to be anchored to some target object.

Although a better approach is to make an invisible widget instead (ALT+SHIFT+W), anchor that to your target object, and the label can be added as a child so that you can offset it as needed.