I making a 2D game. The left 1/4 of the screen is a UI panel showing game stats. The right 3/4 of the screen is a view port showing a portion of the game play field. To start the game, I would like to place the player in the center of the view port. I could eyeball it using the Unity editor, but I would prefer to do it in script (C#). The UI panel’s canvas is in Screen Space - Overlay Render Mode.
I found the panel’s width in myPanel.GetComponent().rec.width. This appears to be in pixel units. I need to offset the player by a relative number of world units. Is there a Unity library function available to perform this conversion?
lpt_rt is the RectTransform of the UI panel that takes up the left 1/4 of the screen. Do the math in screen coordinates. Then convert the screen coordinate to a world coordinate
before applying to the camera postion.