Minimap Issue - pixelRect

Hi guys, i have ecountered an issue with pixelRect when i tried to script my minimap. Everything is working just fine except when i run game pixel rect isn’t where it should (i think be), i mean pixelRect of the “thisCamra” is always in left bottm corner of the screen.

Here is the code:

public Camera thisCamera;
    public Camera mainCamera;

    void Start () {
        thisCamera = GetComponent<Camera> ();

    }
    void Update () {
       
        if (thisCamera.pixelRect.Contains (Input.mousePosition)) {
           
             if(Input.GetKey (KeyCode.Mouse0)) {
                Ray MouseRay = thisCamera.ScreenPointToRay (Input.mousePosition);
                RaycastHit hitInfo;
                Vector3 newPosition = MouseRay.origin;
                newPosition.y = mainCamera.transform.position.y;
                mainCamera.transform.position = newPosition;
            }
        }
    }

Do you have any ideas y i doesnt work and how to fix it?
(there is screen in attachemnt that explains a little more)

As far as I know PixelRect has the 0,0 at the bottom left corner of the screen and Input.mousePosition has 0,0 as the top-left. You would need to pass your mouse position like this:

new Vector2( Input.mousePosition.x , Screen.height - Input.mousePosition.y )
1 Like