Hello,
I have got a box that's centred on the screen using GUILayout. How can I have a button inside that box that's going to be aligned in the centre of that box?
Here's my code which works for the box, but doesn't work for the button:
function OnGUI()
{
if (!isGameOver)
{
scoreAndLifesText.text = "Score: " + gameScore + " Lifes: " + gameLifes;
} else
{
var boxText : String;
if (isNewHighscore)
{
boxText = "Congratulations!
New highscore: " + highscore;
} else
{
boxText = "Your score: " + gameScore + "
Highscore: " + highscore;
}
GUILayout.BeginArea( Rect( 0, 0, Screen.width, Screen.height ) );
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Box(boxText, GUILayout.Width(500), GUILayout.Height(200) );
GUILayout.BeginArea( Rect( 0, 0, 500, 200 ) );
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Play Again", GUILayout.Width(100) ) ) {
RestartLevel();
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.EndArea();
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
GUILayout.EndArea();
} }
Thanks.
It shows up, but in the wrong place.
– anon8995453