- Home /
Margin not working on UILayout.BeginVertical("Window")
I'm trying to make a simple GUI using GUILayout.BeginVertical (and GUILayout.EndVertical) and it places the controls I add at the top left corner of the screen.
I want to add a margin so that it's not exactly in the corner. I want to avoid using GUILayout.BeginArea because that requires a width and length and I'm not sure how large the GUI will end up being.
I copied a new GUISkin file from a new project into my existing project to use so that it contains the default settings and not any modified settings.
Then in my script I make a public variable for the GUISkin I copied and renamed and in my code set the GUI.skin = customSkin.
I can then make changes to the GUISkin in the inspector when playtesting and see how the different settings affect the GUI controls.
i can't seem to get the margin to work when placing a GUILayout.BeginVertical("Window Text", "Window").
Part of what I don't understand is that if I place a GUILayout.Label("Label Text") before the GUILayout.BeginVertical("Window Text", "Window") then I CAN change the margin settings of the window in the customSkin and see the changes take place during playtesting.
Why is this?
And is there a way to get the margin for the "Window" control working without using code that requires entering a width or height?
Sorry for the long explanation but I wanted to be as clear as i could.
Here is my code example:
 // Date: 2022-01-28
 // Info: ...
 
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CameraManagerTypeSwitcher : MonoBehaviour
 {
 
     // Variables
 
     public GUISkin customSkin; // Set in inspector.
 
     // private Rect rectBeginArea = new Rect(25, 25, 500, 500); // x, y, w, h
 
     // On GUI
 
     void OnGUI()
     {
 
         GUI.skin = customSkin; // Test changes in inspector during playtesting to see effects.
         
         // GUILayout.BeginArea(rectBeginArea); // Don't want to use this because it uses dimensions.
         
         // GUILayout.Label("Label Text"); // Uncommenting this makes the margin work...why?
 
         GUILayout.BeginVertical("Window Text", "Window");
         GUILayout.Label("Label Text");
         GUILayout.EndVertical();
 
         // GUILayout.EndArea();
 
     }
     
 }
 
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                