生成的对象上的Unity null?

时间:2018-08-12 10:51:22

标签: c# unity3d c#-4.0

在Unity C#中,我要突出显示一个十六进制。从理论上讲,它应该与

一起使用
    board[x, y].objectonhex = new PawnClass(...);
    if(board[x, y].objectonhex != null)

,但结果是:null。我已经Debug.Log(objecthex)并且result不正常。在应用新对象之前,它为Null,然后为null。我已经尝试过其他测试是否为null的方法,例如:Equals(null)等。(在C#4.0中为null无效)

这是完整的代码:

public void ShowOn()
{
    for (int x = 0; x < size; x++)
        for (int y = 0 + x % 2; y <= size * 2; y += 2)
            if (board[x, y].objectonhex != null)
                Debug.Log(x + "|||" + y);
}

public void Test()
{
    Debug.Log(board[5, 11].objectonhex);
    board[5, 11].objectonhex = new PawnClass.Character(0, "SS", UniqueID.alien, 50, 50, 50, 50, 50, 50, 50, 3, 1, 1, 5);
    Debug.Log(board[5, 11].objectonhex);

    board[5, 9].objectonhex = new PawnClass.Character(0, "SB", UniqueID.nazi, 50, 50, 50, 50, 50, 50, 50, 2, 1, 1, 5);
    board[7, 3].objectonhex = new PawnClass.Character(0, "SU", UniqueID.alien, 50, 50, 50, 50, 50, 50, 50, 3, 1, 1, 5);

    ShowOn();
    //highLight(board[5, 11]);
}

0 个答案:

没有答案