我的代码看起来像:if(Input.GetButtonDown(“Fire2”))
建筑是公共GameObject,我通过团结Inpsector添加 . 在使用右键单击后,GameObject被实例化,但透明变量具有null而不是实例化的GameObject . 如果我将透明类型更改为Object并删除'as GameObject',那么一切都很好 .
Ok, I find out what was wrong . 我的建筑不是GameObject,它是Building(继承MonoBehaviour的类,所以有游戏对象本身) . 现在我实例化building.gameobject,一切正常 .
1 回答
事实证明,我发起了'building'作为Building类(Building是我自己的类并继承了MonoBehaviour),而不是GameObject,因此Unity将问题放入GameObject . 它现在看起来像这样:
}