I have the world coordinates and pixel size of a section of the screen that I want to draw a camera viewport over. Think minimap. I hand placed the normalized viewport rect for the designed aspect ration but need to support many different aspect ratios. since the rect for displaying a camera is normalized… a .25 width is different between different aspect ratios.
I cannot, for the life of me figure out how to get a specific world position and pixel height/width to convert to a normalized viewport that works in any aspect ratio. I only really need to adjust the width.
Here is what I have so far… totally doesn’t work
Camera miniCamera = GetComponent<Camera>();
Vector3 pos = Camera.main.WorldToScreenPoint(
new Vector3(myPosition.x - (myWidth/2f), 0f, 0f));
miniCamera .pixelRect= new Rect(pos.x, miniCamera.rect.y, imgSprite.width, imgSprite.height);