Hi, Im trying to make my GUI resolution independent for certain low screen resolution.
Here is my code:
public void GUIMatrix()
{
Fraction res = new Fraction((long)Screen.width, (long)Screen.height);
float width_ratio;
float height_ratio;
Fraction.ReduceFraction(ref res);
if (Screen.width < 1300 && Screen.height < 1000)
{
if ((res.Numerator / res.Denominator) < 1.55) // Not widescreen
{
width_ratio = 1024f;
height_ratio = 768f;
}
else // Widescreen
{
width_ratio = 1280f;
height_ratio = 800f;
}
}
else
{
width_ratio = (float) Screen.width;
height_ratio =(float) Screen.height;
}
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3((1.0f * Screen.width)/width_ratio, (1.0f * Screen.height)/height_ratio, 1f));
}
The function is called OnGUI the first time, but when I press play in the editor I receive the following error:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUI.set_matrix (Matrix4x4 value) (at E:/BuildAgent/work/68355d6e5d19d587/Runtime/Export/Generated/GUI.cs:64)
I really don't know what produces the issue... Anyone can help??
Thanks.
asked
Oct 20 '10 at 11:56 AM
user-710 (google)
34
●
7
●
7
●
13