Scaling the GUI matrix in mobile causes buttons to be off

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. Not sure if not using it would solve anything.

@Jopan Hello from 2020! Did you find a solution to this?