I’m working on a golfing game and I need to create some type of score card on the gui. Is there a way to easily create a spreadsheet within unity? Or am I going to have to use screen coordinates to set up each and every variable?
Molix
3
Well, you’ll need to set up each variable at least once, say as a single row, but then just put them in a loop, and increase the y position. e.g.
GolfPlayerInfo[] players;
float rowHeight = 20.0f;
for( int i=0; i<players.Length; ++i )
{
GUI.Label( new Rect( 0, i*rowHeight, 150, rowHeight ), players*.name );*
GUI.Label( new Rect( 151, irowHeight, 100, rowHeight ), players.score );*
GUI.Label( new Rect( 251, irowHeight, 100, rowHeight ), players.currentHole );*
}
Using GUILayout with BeginHorizontal/BeginVertical and a fixed width GUILayoutOption means you can avoid coordinates altogether, e.g.
GolfPlayerInfo[] players;
float[] columnWidths = { 150, 100, 100 };
for( int i=0; i<players.Length; ++i )
{
GUILayout.BeginHorizontal();
GUILayout.Label( players*.name, GUILayout.Width( columnWidths[0] ) );*
GUILayout.Label( players*.score, GUILayout.Width( columnWidths[1] ) );*
GUILayout.Label( players*.currentHole, GUILayout.Width( columnWidths[2] ) );*
GUILayout.EndHorizontal();
}
(this code is off-the-cuff but should point in the right direction)
system
2
You can use a GUI Texture and replace the texture with what ever texture you want. And when you say spreadsheet, did you mean a sprite spread sheet and how to animate it?