Hello Guest

Author Topic: Position menu at world position  (Read 3915 times)

Vartib

  • Newbie
  • *
  • Posts: 21
    • View Profile
Position menu at world position
« on: January 20, 2014, 03:15:35 am »
I'm using two cameras, the first to render the world and a second to render the UI elements. I have a menu that is rendered by the second camera that I want to lock to a specific world position/object. The idea is that you can select an object to highlight it and then move the first camera around so you scroll along the world but still have the menu stay at the position of the object.

I thought using "secondCamera.WorldToScreenPoint (worldPosition)" would do the trick, but it gives me a value that's wildly off. Maybe something else?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Position menu at world position
« Reply #1 on: January 20, 2014, 11:51:19 am »
You will need to convert worldPosition between cameras as the 2 cameras will not be seeing the same part of the world. The one common thing between the cameras will be screen position, so you can do something like this

Code: [Select]
Vector3 cam2WorldPos = cam2.ScreenToWorldPoint(cam1.WorldToScreenPoint( worldPos ));