Scaling the GUI matrix in mobile causes buttons to be off (515509)

Hello, I am making a mobile app using unity’s GUI exclusively. I am targeting android. I want the app to work on any size screen, so I am scaling GUI.matrix to make the GUI appear the same on any resolution.

private float originalWidth = 1024.0f;
private float originalHeight = 600.0f;
 
void Start ()
{
     scale.x = Screen.width / originalWidth;
     scale.y = Screen.height / originalHeight;
     scale.z = 1.0f;
}
 
void OnGUI ()
{
     GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
 
     // GUI Code
}

This worked great. Then I noticed that when I tried to touch the buttons that I couldn’t. I believe the buttons only work when I push the area that the buttons are before they are scaled into place.

After searching a bit I found a bit of a hack that worked pretty good, but only for mouse clicks.

void OnGUI ()
{
     GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
 
    // The hack
    if ( Event.current.type == EventType.Layout  Event.current.clickCount == 0 )
    {
         GUI.matrix = Matrix4x4.identity;
    }
 
    // GUI Code
}

This didn’t work for touch, however. I don’t really understand how the “hack” worked, but I tried changing it to this.

 if ( Event.current.type == EventType.Layout  Input.touchCount == 0 )
     {
          GUI.matrix = Matrix4x4.identity;
     }

That had no effect, however.

So my question is basically, how can I get the scaling to work properly on android and also be able to properly click/touch the buttons?

I am using GUILayout by the way.

have you found a solution? I too am experiencing the same issue

Does no one know the answer?
It would be helpful

If you are setting the GUI.matrix, then you are telling Unity how to change the resolution of the GUI components. This applies to the rendering of those objects. This doesn’t affect the touch, and I have no idea what the hack is supposed to do. Instead, I’d recommend that you compute the position and width and height of the GUI components based on the screen width and height and don’t monkey around with the matrix.