- Home /
Second Camera Position on Viewport to UI Element Position on Screen
Hello, I have a UI image that follows the player on the screen. I also have a second camera (like a mini map). How would I set the rect position of the second camera to the UI image position on the screen so that wherever the UI image goes in the screen, the second camera will follow. Thanks
Comment
Answer by Gkrumbach07 · Dec 29, 2016 at 05:37 PM
Ok, I found that you use ScreenToViewportPoint and pass through the UI element anchored position, it will line up properly. But I had to set the UI element's anchored position to the bottom left.
Answer by Aily · Jan 14, 2018 at 03:36 PM
public Canvas canvas;
public RectTransform fitViewport;
void Update()
{
Camera.main.pixelRect = RectTransformUtility.PixelAdjustRect(fitViewport, canvas);
}