Time for action – centering the game grid horizontally
By dropping two more FlexibleSpace
function calls into your BuildGrid()
function, you can horizontally center the grid on the screen.
Add a
GUILayout.FlexibleSpace();
function call between theGUILayout.BeginHorizontal()
andGUILayout.EndHorizontal()
calls:function BuildGrid() { GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); for(i=0; i<rows; i++) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); for(j=0; j<cols; j++) { // Again, the code here has been removed for the sake of brevity } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.FlexibleSpace(); GUILayout.EndVertical(); }
Save the script and test your game. Hooray! The game grid is now centered on the screen, both horizontally and vertically.
What just happened – coding like a ninja
What we've done here is stuck two springy...