GUI labels and buttons overlapping | how can I fix this?

So I am using a list of GUILayout labels and buttons. If I don’t use an area it works perfect, the labels and buttons are displayed below each other (in the top left corner, but I want them to be in the middle of the screen) but when I use an area they all use the same position and just overlap each other. If anyone could help me (please don’t make it too hard, I am still a noob in programming :slight_smile: ), I would really appreciate it.

void OnGUI(){
    
    		Event e = Event.current;
    		if (inputManager != null) {
    
    			for (int i = 0; i < inputManager.Count; i++) {
    
    				GUILayout.BeginArea(new Rect(posX, posY, sizeX, sizeY));
    				GUILayout.BeginHorizontal ();
    				GUILayout.Label (inputManager *.keyName, labelStyle);*

_ if (GUILayout.Button (inputManager .key, keyStyle)) {_

* key = i;*
* change = true;*

* }*

* GUILayout.EndHorizontal();*
* GUILayout.EndArea ();*
}
* }*
This is part of the code I use for customizable controls.

I don’t use the legacy gui, but I guess you have to put Area and Horizontal outside the for-loop:

GUILayout.BeginArea(new Rect(posX, posY, sizeX, sizeY));
GUILayout.BeginHorizontal ();
for (int i = 0; i < inputManager.Count; i++) 
{
    GUILayout.Label (inputManager *.keyName, labelStyle);* 

if (GUILayout.Button (inputManager .key, keyStyle))
{
key = i;
change = true;
}
}
GUILayout.EndHorizontal();
GUILayout.EndArea ();

Look athe the images and itll help you with your Custom Inspector Layout How to clamp EditorGUILayout controls' width ? - Unity Answers