Another GUI.matrix problem

I take an objects screen position with;

scrPos = Camera.main.WorldToScreenPoint (transform.position);

Then when i use it in gui rect, it works allright. But when i set the gui.matrix to scale depending on the resolution, the scrPos vector slightly offsets my gui.

I believe i need to scale the scrPos vector according to the gui matrix too, but when i take a crossproduct of the vector, it just doesnt work. Please help.

To be more specific:

scrPos = Camera.main.WorldToScreenPoint (transform.position);
//Sets gui scale according to screen width and height ratio
GUI.matrix = Core.Gui.SetGuiMatrix();

GUI.Box (new Rect (scrPos.x - angSize, Core.Scr.height - scrPos.y - angSize, angSize, angSize), angSize.ToString());

In the above snippet, angSize is an objects screen size in pixels and im definitely sure the returned value is correct.

without the gui.matrix function, it all works correctly.
But with gui.matrix function scrPos values offset slightly.

Any help would be appreciated.

What’s the reason for re-scaling GUI.matrix? (Particularly if it works correctly when you don’t do that…)

Anyway, if you rescale GUI.matrix, you’re effectively changing the coordinate space that scrPos is in so yes, you’ll need to adjust scrPos accordingly. You need to apply the same scaling to those coordinates as you applied to the screen coordinate system via GUI.matrix.

Reason is, i have a default resolution of 800x600 where i adjust the background gui according to and gui.matrix allows me to scale it automatically when user changes resolution. Meanwhile i have objects in scene where user can interact with, coded in a seperate gui call.

I did also try to scale the scrPos with the same scale of gui but still it just gives very odd results and offsets the user interaction gui.