I've this simple script in Unity3d:
#pragma strict
public var topLeft : UnityEngine.UI.Button;
public var topCenter : UnityEngine.UI.Button;
public var topRight : UnityEngine.UI.Button;
public var midLeft : UnityEngine.UI.Button;
public var midCenter : UnityEngine.UI.Button;
public var midpRight : UnityEngine.UI.Button;
public var bottomLeft : UnityEngine.UI.Button;
public var bottomCenter : UnityEngine.UI.Button;
public var bottomRight : UnityEngine.UI.Button;
private var x = "X";
private var o = "O";
function Start () {
var board = [[topLeft, topCenter, topRight], [midLeft, midCenter, midpRight], [bottomLeft, bottomCenter, bottomRight]];
for (var i = 0; i < board.length; ++i) {
var row = board[i];
for (var j = 0; j < row.length; j++) {
var button = row[j];
button.onClick.AddListener(function() { onTileClicked(button); });
}
}
}
function onTileClicked(tile : UnityEngine.UI.Button) {
Debug.Log("Click click!");
}
Here is how I reference the buttons:
Why are all the buttons in 'board' variable null even if I referenced them through the GUI (the red rectangle in the image)?