- Home /
GUI.matrix - invalid matrix
Just trying to establish the basics of setting the GUI to adjust, however I can't even get GUI.matrix to work.
var customSkin : GUISkin; var nativeHorizontalResolution = 1920; var nativeVerticalResolution = 1080;
function OnGUI () { GUI.skin = customSkin; var Rwide = Screen.width; var Htall = Screen.height; Debug.Log("Resolution is:" + Rwide + "wide by" + Htall + "high"); //Out to console what our resolution is. GUI.matrix = Matrix4x4.TRS(Vector3(0,0,0), Quaternion.identity, Vector3(Screen.width / nativeHorizontalResolution, Screen.height / nativeVerticalResolution, 1)); }
I am trying this based on what is in the 3D Platformer Tutorial, but all I get is the following error:
Ignoring invalid matrix assigned to GUI.matrix - the matrix needs to be invertible. Did you scale by 0 on Z-axis?
I understand TRS (trans/rot/scale) and how it operates. What I don't understand is why it believes I am going negative (hence why I shoot out to log to see my Res to make sure), or that I am scaling in Z, as I am certainly not scaling Z. As for being invertible, well why does this code work other places and not here?
In the tutorial they even have it dividing against 1200 twice; which doesnt work and I had hoped the error in there was the reason:
GUI.matrix = Matrix4x4.TRS (Vector3( 0, 0, 0 ), Quaternion.identity, Vector3 (Screen. height / nativeVerticalResolution , Screen.height / nativeVerticalResolution , 1));
Any light shed upon why I am generating this error would be great, Thanks.
Answer by Eric5h5 · Dec 07, 2010 at 06:37 AM
"Screen.width / nativeHorizontalResolution" will not give you the result you want, as long as both of those are integers. You need at least one to be a float in order to get a float as a result instead of an integer. JS doesn't have an inline way to cast integers to floats, so you can use parseFloat or just add 0.0..."(Screen.width + 0.0) / nativeHorizontalResolution". Even though it also works to make nativeHorizontalResolution a float, I would recommend not doing that, since the resolution is inherently an integer, and it could potentially cause problems elsewhere.
Answer by Argenex · Dec 07, 2010 at 06:24 AM
And the answer is....
var nativeHorizontalResolution = 1920.0;
var nativeVerticalResolution = 1080.0;
Guess it wants it to be float. Which is odd that it works within the 3D Platformer Tutorial, and works using screen.height twice..
Doing this removed the error.