x


Can't set GUI.matrix...

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.

more ▼

asked Oct 20 '10 at 11:56 AM

user-710 (google) gravatar image

user-710 (google)
34 7 7 13

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Solved!!

I was calling the function OnGUI() and Update(), and it can obly be called OnGUI().

more ▼

answered Oct 20 '10 at 12:23 PM

user-710 (google) gravatar image

user-710 (google)
34 7 7 13

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3694
x81
x17

asked: Oct 20 '10 at 11:56 AM

Seen: 1827 times

Last Updated: Oct 20 '10 at 11:56 AM