GUILayout three buttons alligned horizontally with no spaces between them

154424-ss.jpg

I’m trying to build a custom EditorWindow in Unity and I want to have the effect like in the picture with the buttons acting like tabs.

I tried to place the buttons horizontally and have negative spaces between them but is not quite the effect I want. Below is my code.

    GUILayout.BeginHorizontal();
    GUILayout.FlexibleSpace();

    if (GUILayout.Button("Heightmap")) { }
    GUILayout.Space(-10);
    if (GUILayout.Button("Vegetation")) { }
    GUILayout.Space(-10);
    if (GUILayout.Button("Details")){ }

    GUILayout.FlexibleSpace();
    GUILayout.EndHorizontal();

As you have already figured out you can use GUILayout.Toolbar which gives you all the buttons as one control. However if you want individual buttons you just have to make sure you set the margin of the button style you use to 0. However keep in mind that the usual button background image does contain a border. So even with no space between the buttons they don’t really “blend” into each other since the image represents single buttons. So you could just create your own button images.

For more information you might want to have a look at my IMGUI crash course