Author Topic: Question on "Making a UI element stay in a specific place"  (Read 2324 times)

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Question on "Making a UI element stay in a specific place"
« on: October 11, 2014, 04:08:06 AM »
Hello everyone, I'm looking for some general guidance on creating a specific sort of UI element behavior with NGUI:

In Detail:
Essentially, I've got a target reticle that normally stays in a set position on the player's screen. When the camera moves, the reticle moves along with it (well really, it stays in place because its using NGUI and its being overlayed). But, I'm trying to make a system where the player can "unlock" the target reticle from the camera view, essentially allowing the player to rotate the camera freely and have the target reticle "remain where it was" until the player "locks" the camera back to the reticle.

I was wondering if anyone has done something like this before, or what approach you would take (2d ui? 3d ui? heirarchy setups, etc). I'm not looking for full code, just a good way to approach the issue. I've though about ways of just "moving it offscreen" but those seem clunky, I've also though about making the reticle invisible when the player wants to free-move the camera which is simple, but not quite what I'm going for.

Any ideas are appreciated. Thank you for reading.
« Last Edit: October 11, 2014, 04:19:43 AM by blitzer »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question on "Making a UI element stay in a specific place"
« Reply #1 on: October 11, 2014, 04:54:21 AM »
You can either use UIFollowTarget to make a 2D widget follow a 3D object, or just anchor it to the 3D object.

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: Question on "Making a UI element stay in a specific place"
« Reply #2 on: October 11, 2014, 05:11:11 AM »
I put up another diagram of what my setup is looking like in case it helps clarify things. I suppose what I'm looking for is not so much a "tacking" behavior, as much as the ability to just keep the UI element "in the same spot".

You can either use UIFollowTarget to make a 2D widget follow a 3D object, or just anchor it to the 3D object.
-> I'm not understanding in either case how the UI element would remain at the correct angle / distance to the camera if it is tracking or anchored to moving 3d objects (really, how "3d tracking" is converted to 2d space), any clarification is appreciated.
« Last Edit: October 11, 2014, 07:04:55 PM by blitzer »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question on "Making a UI element stay in a specific place"
« Reply #3 on: October 11, 2014, 07:03:56 PM »
Angle/distance? 2D elements have no distance. They're on the 2D plane. transform.OverlayPosition can also be used to position a 2D object on top of a 3D one visually.

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: Question on "Making a UI element stay in a specific place"
« Reply #4 on: October 11, 2014, 07:09:15 PM »
I see your point, and I guess what I'm trying to understand is how to keep that UI element in the same place / rotation, since I'm not actually looking to make that element "track" anything. Perhaps I could create  a empty Game Object that is a child of the ship, and have the UI element look at / track that Game Object.

As always, thank you for your responses.