3
\$\begingroup\$

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:

enter image description here

Why are all the buttons in 'board' variable null even if I referenced them through the GUI (the red rectangle in the image)?

\$\endgroup\$
1
\$\begingroup\$

Turns out it was a bug in Unity.. All I had to do was restart the IDE.. Bad start from Unity.

\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.