Advertisement
MBrendecke

Buttons

Mar 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. public class TestScript : MonoBehaviour {
  4.     public GUIStyle style;
  5.    
  6.     private const int MAX_ROWS = 16;
  7.     private const int MAX_COLUMNS = 8;
  8.  
  9.     private const int BUTTON_WIDTH = 100;
  10.     private const int BUTTON_HEIGHT = 50;
  11.  
  12.     void OnGUI() {
  13.         GUI.skin.button = style;
  14.  
  15.         for (int row = 0; row < MAX_ROWS; row++) {
  16.             for (int coloumn = 0; coloumn < MAX_COLUMNS; coloumn++) {
  17.                 int clicked = row * MAX_COLUMNS + coloumn;                
  18.                 GUI.color = (clicked % 2 == 0) ? Color.red : Color.green;
  19.                
  20.                 if (GUI.Button(new Rect(100 + (coloumn * BUTTON_WIDTH), 100 + (row * BUTTON_HEIGHT), BUTTON_WIDTH, BUTTON_HEIGHT), "Click Me!"))
  21.                     Debug.Log("Geklickt:" + (clicked));
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement