2D Toolkit Forum

2D Toolkit => Support => Topic started by: Vartib on January 20, 2014, 03:15:35 am

Title: Position menu at world position
Post by: Vartib 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?
Title: Re: Position menu at world position
Post by: unikronsoftware 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 ));