【问题标题】:GameObject.Find not working on Player in DontDestroyOnLoadGameObject.Find 在 DontDestroyOnLoad 中对 Player 不起作用
【发布时间】:2020-12-18 16:42:48
【问题描述】:

带有脚本GamePlayerManager的玩家对象由NetworkLobbyManager在Lobby使用后创建GameScene时设置

var conn = RoomPlayers[i].connectionToClient;
var gameplayerInstance = Instantiate(gamePlayerPrefab);
gameplayerInstance.SetDisplayName(RoomPlayers[i].DisplayName);
gameplayerInstance.SetPosition(RoomPlayers[i].Position);
NetworkServer.Destroy(conn.identity.gameObject);
NetworkServer.ReplacePlayerForConnection(conn, gameplayerInstance.gameObject);

GamePlayerManager 上的OnStartClient 中,我尝试使用myHand = GameObject.Find("myHand"); 引用GameObjects,但之后myHand 为空。 此刻我的层次结构:Hieracrchy

难道不是因为播放器处于 DontDestroyOnLoad 中吗? 而且我听说 .Find 不是查找参考的最佳选择,但是什么是?

【问题讨论】:

    标签: c# unity3d mirror unity3d-unet


    【解决方案1】:

    现在我发现 OnStartClient 被提前调用以使场景存在,在转换更改之前使用了 Find 方法并且它起作用了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多