I have a GUILayout.TextField where I needed to center the text. I added a GUIStyle as an argument where
centerStyle = new GUIStyle
{
alignment = TextAnchor.MiddleCenter,
};
However, this causes the background box of my GUILayout.TextField to disappear and the text becomes misaligned.
Before centering: Before
After centering: After
(Sorry i can't really post pictures yet)
Here's the code where i created the TextField:
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
guildName = GUILayout.TextField(guildName, 20, centerStyle, GUILayout.Width(200));
bool canCreate = true;
foreach (string word in guilds)
{
if (guildName == word)
canCreate = false;
}
if (GUILayout.Button("Create", GUILayout.Width(75)) && canCreate)
{
GameManagerVik.CreateGuild(guildName);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
Any help or advice on my codes will be much appreciated, thanks in advance!