Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to center buttons and anchor to bottom

Discussion in 'Immediate Mode GUI (IMGUI)' started by steveg2357, Oct 16, 2014.

  1. steveg2357

    steveg2357

    Joined:
    Aug 21, 2014
    Posts:
    34
    I'd like to create a centered row of buttons and anchor it to the bottom of the screen (the following is a nominal example).

    Screen.jpg

    When I do the following in the OnGUI function in a UnityScript class that extends EditorWindow, it creates a row of buttons that are left aligned and are placed after the last GUI control.

    Code (JavaScript):
    1. EditorGUILayout.BeginHorizontal();
    2. var myButton1 = GUILayout.Button("Done", GUILayout.ExpandWidth(false));
    3. var myButton2 = GUILayout.Button("Cancel", GUILayout.ExpandWidth(false));
    4. EditorGUILayout.EndHorizontal();
    Is there a way to modify or use something similar to the above without specifying one or more rectangles with coordinates relative to the screen size?
     
  2. Avalion

    Avalion

    Joined:
    May 2, 2012
    Posts:
    34
    You can use GUILayout.FlexibleSpace() to align elements where you want on GUI.

    Avalion