- Home /
gui.box not resize based on screen resolution using c# code
Am using gui.box and button based on matrix but not resized. when using small screen size like 480*800 text came out side of screen how to solve this problem my code
void OnGUI() { ---other code AutoResize();
if (showCentralButton) { centralButton.viewRectangle = new Rect(Screen.width (actualMenuPosition.x - actualBtnSize / 2)-2, (Screen.height actualMenuPosition.y) - (Screen.width actualBtnSize /2)-75, Screen.width actualBtnSize+100, Screen.width * actualBtnSize+100); GUI.Button(centralButton.viewRectangle, "", centralButton.buttonStyle); ---//other code GUI.Box(new Rect(positionBtn.x+130, positionBtn.y, Screen.width, Screen.width ), part.name, part.textStyle); //
public static void AutoResize() {
Vector2 resizeRatio = new Vector2((float)Screen.width / (float)Screen.width, (float)Screen.height / (float)Screen.height); GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(resizeRatio.x, resizeRatio.y, 1.0f)); }
thanks
Please post code using the code sample tags- this isn't readable. Also, please don't use OnGUI for runtime UI, use the Unity UI system (canvasses and such) ins$$anonymous$$d. This is terribly inefficient and adds draw calls for every single element being rendered to the screen. If this is for an editor window or custom inspector ins$$anonymous$$d, please indicate as much- there are editor tools that may make this task easier.