您好,我正在尝试通过实例化新玩家将角色加载到游戏场景中。但是当我尝试加载他时,我得到一个空引用异常。具有空引用的代码行是
newPlayer.GetComponent<Player>().Load (PlayerLoadUpdateName, PlayerLoadUpdateInfo, PlayerLoadUpdatePosition);
更具体地说,无效的东西是:
GetComponent<Player>()
如何使其不为空?
定义newPlayer的还有:
GameObject newPlayer = (GameObject)Instantiate (PlayerObj, PlayerLoadUpdatePosition, new Quaternion ());