MBrendecke icon

Buttons

MBrendecke | PRO | 03/25/18 03:56:37 PM UTC | 0 ⭐ | 391 👁️ | Never ⏰ | []
C# |

830 B

|

None

|

0 👍

/

0 👎

using UnityEngine;
 
public class TestScript : MonoBehaviour {
    public GUIStyle style;
    
    private const int MAX_ROWS = 16;
    private const int MAX_COLUMNS = 8;
 
    private const int BUTTON_WIDTH = 100;
    private const int BUTTON_HEIGHT = 50;
 
    void OnGUI() {
        GUI.skin.button = style;
 
        for (int row = 0; row < MAX_ROWS; row++) {
            for (int coloumn = 0; coloumn < MAX_COLUMNS; coloumn++) {
                int clicked = row * MAX_COLUMNS + coloumn;                
                GUI.color = (clicked % 2 == 0) ? Color.red : Color.green;
                
                if (GUI.Button(new Rect(100 + (coloumn * BUTTON_WIDTH), 100 + (row * BUTTON_HEIGHT), BUTTON_WIDTH, BUTTON_HEIGHT), "Click Me!"))
                    Debug.Log("Geklickt:" + (clicked));
            }
        }
    }
}

Comments