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 Answer 1

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
  • 4
    \$\begingroup\$ Consider reporting the bug. \$\endgroup\$ Commented Apr 23, 2015 at 11:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.