i\'m trying to scale a GUI.TextArea.
the code block works in OnGui function. But when i change screen size , the textArea won\'t be on correct position and size.
You should try to use new GUI / Canvases, but if you're determined to use the older immediate-mode GUI for some reason, you can do this:
public static Vector3 GUIScale{
get{
float normalWidth = 1024; //Whatever design resolution you want
float normalHeight = 768;
return new Vector3(Screen.width / normalWidth, Screen.height / normalHeight, 1);
}
}
public static Matrix4x4 AdjustedMatrix{
get {
return Matrix4x4.TRS(Vector3.zero, Quaternion.identity, GUIScale);
}
}
void OnGUI(){
GUI.matrix = AdjustedMatrix;
(... GUI drawing code ...)
}
Which will make the GUI always take up the same amount of the screen. It will work, but it might look pretty bad at higher resolutions and different screen aspect ratios than the "normal" one you design for. You'll also have to use the "normal" resolution numbers instead of Screen.width and Screen.height when drawing things.