**Hi all,**
**i get this error in the xcode log:**
Ignoring invalid matrix assinged to GUI.matrix - the matrix needs to be invertible. Did you scale by 0 on Z-axis?
**This is the code I used:**
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GUISizer {
static float WIDTH = 720f;
static float HEIGHT = 1280f;
static List stack = new List ();
static public void BeginGUI()
{
stack.Add (GUI.matrix);
Matrix4x4 m = new Matrix4x4 ();
float w = (float)Screen.width;
float h = (float)Screen.height;
float aspect = w / h;
float scale = 1f;
Vector3 offset = Vector3.zero;
if(aspect < (WIDTH/HEIGHT)) { //screen is taller
scale = (w/WIDTH);
offset.y += (h-(HEIGHT*scale))*0.5f;
} else { // screen is wider
scale = (h/HEIGHT);
offset.x += (w-(WIDTH*scale))*0.5f;
}
Debug.Log ("Offset: " + offset + " aspect " + aspect + " scale " + scale);
m.SetTRS(offset,Quaternion.identity,Vector3.one*scale);
GUI.matrix *= m;
}
static public void EndGUI()
{
GUI.matrix = stack[stack.Count - 1];
stack.RemoveAt (stack.Count - 1);
}
}
**Everything works fine on PC and Android.**
**Another problem I'm facing is that buttons on the upper edge of the screen aren't responding correctly.
To explain it better I've uploaded a edited screenshot.
Only the green area is clickable.
The Red area opens buttons from the lower half of the screen.. as if there's another screen squeezed in the y.. :/**
![alt text][1]
[1]: /storage/temp/36311-screen+shot+2014-12-02+at+17.45.23.jpg
**It's really a strange behaviour.
I hope that someone has an idea what's going on there.**
**best regards
Dennis**
ps. that's a old project and i don't want to change everything to new unity gui
↧