- Home /
GUI Matrix problem only on iOS
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<Matrix4x4> stack = new List<Matrix4x4> ();
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.
Comment
Have you tried this?
m.SetTRS(offset,Quaternion.identity,new Vector3(scale,scale,1f));
GUI.matrix = m;
Regarding the second problem, it is recommended to submit as a separate question. The Unity Answers FAQ lists some of the benefits of doing so.
I've tried it now with no success..
Xcode is still saying: Ignoring invalid matrix assinged to GUI.matrix - the matrix needs to be invertible. Did you scale by 0 on Z-axis?
That's really frustrating.. i dont know what to do now
I created a test project with your script then added some code to call BeginGUI and EndGUI. Built the app for iOS in Xcode and installed on my iPod. Was unable to reproduce the error. Are you receiving the error when building the app in Xcode?