Code (csharp): var originalWidth = 1024; function OnGUI () { var guiScale = Screen.width/originalWidth; GUI.matrix = Matrix4x4.Scale(guiScale*Vector3.one); } I took this from an older topic and added an original width variable, but I get the error: "Ignoring invalid matrix assinged to GUI.matrix - the matrix needs to be invertible. Did you scale by 0 on Z-axis? UnityEngine.GUI:set_matrix(Matrix4x4)" I'm totally stumped since there's absolutely no documentation on GUI.matrix. Help! Thanks.
I used this code to scale a GUI window a while ago: Code (csharp): GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis(0, new Vector3(0, 1, 0)), new Vector3(FloatXSize, FloatYSize, 1)) From what i remember, I was just Lerping the X and Y resize values to 'zoom' the window. cheers shaun
Use Matrix4x4.TRS(t, r, s) to create your matrix, then provide: t: translation vector value, move along x and y, but not z r: quaternion rotation value, rotate on z, but not x and y s: scale vector value, scale on x and y, but not z Edit: see this thread for another example of how to use GUI.matrix (look for my post near the end). Really quite a handy way to Translate, Rotate and Scale your GUI elements. Note that if you set the GUI.matrix then all GUI calls after that are affected by the matrix, so if you only want some elements affected then set the matrix value, issue your calls, then reset the matrix back to its original value. And yes, this is a weak point in the GUI docs so I'm sorry about that.
The only caveat is that when you scale GUI elements, they don't get filtered (in the way the Expose filters Mac windows) so things can get a bit jagged. Would be good to know if this can be changed.
Alright, I'm getting something that works here. Thanks guys! Okay, new problem. Code (csharp): var tScale = Vector3(1.0*Screen.width/1024, 1.0*Screen.width/1024, 1.0); var tMatrix = Matrix4x4.TRS(tOffset, tRotation, tScale); GUI.matrix = tMatrix; if (reading) { GUI.Box (Rect(262,0,500,150), showup); } This is the code I'm using to scale the GUI, and the box that I'm making appear with it. Now the problem is that I want it to rest near the bottom of the screen, but different resolutions put it in different places, sometimes too high, and sometimes too low. How I got the 262 to be the center point for horizontal was this: 1024 (value I'm scaling by)/2-500 (width of the box)/2.
There is no perspective applied to the GUI when you use Matrix (at least last time I tried it). The Matrix is meant to be used for 2D scaling and rotation. I used 3D rotation and it works, but it's a squash rather than tilt, if you know what I mean. The controls also get a bit funky if you try to use them in Matrix mode with 3D rotations. As of Flash 10 (Apollo), there will be GPU powered 3D (and 'Shaders' via Hydra). They showed off GUI rotation which looked cool. Video is here: http://drawlogic.com/2007/10/02/fla...dobe-image-foundation-and-hardware-rendering/
Just found out the following code doesn't work: Code (csharp): GUI.matrix.SetTRS(...); Instead, the following needs to be used, as HiggyB explained above: Code (csharp): GUI.matrix = Matrix4x4.TRS(...); This behavior doesn't seem to make sense, so I submitted a bug report: http://fogbugz.unity3d.com/default.asp?436724_u8ak8heh95u7injb
Actually that behavior, while undeniably confusing, is correct. GUI.matrix is a property returning a struct. Properties of structs always return a copy of the struct instead of the original (since that is how structs work). Basically, you're applying your SetTRS(...) onto an anonymous copy of the GUI matrix. I do believe that the compiler is supposed to give a warning about this.
Any idea how to apply GUImatrix scaling when Camera.main.WorldToScreenPoint used? Still trying to figure out how to make this work: http://answers.unity3d.com/questions/1384005/how-to-a-scale-worldtoscreenpoint-parts-of-the-gui.html