C# 返回实例化对象时是否为空对象?

C# 返回实例化对象时是否为空对象?,c#,unity3d,gameobject,C#,Unity3d,Gameobject,从GameController创建新的Tetromino时,我返回一个Gameobject,但它返回的是一个空对象。产卵器代码中的日志显示的是正确的对象,但gamecontroller中的日志仅显示对象 产卵器代码: public class Spawner : MonoBehaviour { public GameObject[] Tetrominoes; private List<GameObject> instantiatedTetrominioes = new

从GameController创建新的Tetromino时,我返回一个Gameobject,但它返回的是一个空对象。产卵器代码中的日志显示的是正确的对象,但gamecontroller中的日志仅显示对象

产卵器代码:

public class Spawner : MonoBehaviour
{
    public GameObject[] Tetrominoes;
    private List<GameObject> instantiatedTetrominioes = new List<GameObject>();
    private int index = 0;
    // Start is called before the first frame update
    void Start()
    {
        NewTetromino();
    }

    public GameObject NewTetromino()
    {
       GameObject newObject =  Instantiate(Tetrominoes[Random.Range(0, Tetrominoes.Length)], transform.position, Quaternion.identity) as GameObject;
        instantiatedTetrominioes.Add(newObject);
        index++;
        Debug.Log(instantiatedTetrominioes[index - 1]);
        return instantiatedTetrominioes[index - 1];
    }
}

您还可以在
Spawner
void Start
中调用
newetromino
。因此,您可能会看到
Spawner.Start
->
newteromino
调用的日志,然后当您在
ongamestart
上调用
Spawner.newteromino
时,您会从
newteromino
获得一个空的调试日志,并且从
ongamestart
获得一个“空”调试日志(除了它包含文本“当前”).这可能就是问题所在,谢谢!
void OnGameStarted()
{
    currentBlock = spawner.NewTetromino();
    Debug.Log("current: " + currentBlock);
}