- Home /
Question by
Jakibah · May 14, 2016 at 05:27 PM ·
guiunity 4matrixmatrix4x4.trs
Matrix error
I have this code:
using UnityEngine;
using System.Collections;
public class DrawCanvas : MonoBehaviour {
public float sWidth;
public float sHeight;
public float GUIRatioX;
public float GUIRatioY;
public Vector3 GUIsF;
public GUISkin skinGUI;
public int sizeGUI;
void Start(){
sWidth = Screen.width;
sHeight = Screen.height;
GUIRatioX = sWidth / 1920 * sizeGUI;
GUIRatioY = sHeight / 1080 * sizeGUI;
GUIsF = new Vector3(GUIRatioX,GUIRatioY,1);
}
void OnGUI() {
GUI.skin = skinGUI;
GUI.matrix = Matrix4x4.TRS(new Vector3(GUIsF.x,GUIsF.y,0),Quaternion.identity,GUIsF);
if(Application.loadedLevelName == "Menu"){
if(GUI.Button(new Rect(1,4,50,51),"hello")){
Debug.Log("pressed");
}
}
}
}
But it gives this error:
Ignoring invalid matrix assinged to GUI.matrix - the matrix needs to be invertible. Did you scale by 0 on Z-axis? UnityEngine.GUI:set_matrix(Matrix4x4) DrawCanvas:OnGUI() (at Assets/Scripts/DrawCanvas.cs:27)
Why and how can I slove this???
Comment
Answer by Bunny83 · May 14, 2016 at 06:43 PM
First of all, why do you pass your GUIsF as translation to the TRS method? As far as i can tell that's a scale factor and not a translation. If you only want to scale you might want to use Matrix4x4.Scale instead. Also what values do you get for GUIsF.x
and GUIsF.y
? Are you sure that all values are non-zero?