void Update() { if (readyToStart) { MakeGamePlayer(); } if (refreshData) { foreach (TransformVO tv in dataList) { if (tv.socketId != myId) //내가 아니라면 { GameObject p = null; players.TryGetValue(tv.socketId, out p); if (p == null) //해당 유저는 새롭게 접속한 것이니 갱신해서 넣어준다. { p = MakeRemotePlayer(tv); players.Add(tv.socketId, p); } //생성된 애들에 대해서는 데이터를 갱신한다. PlayerRPC remoteRPC = p.GetComponent <PlayerRPC>(); remoteRPC.SetTransform(tv.point, tv.rotation); } } refreshData = false; } }
private GameObject MakeRemotePlayer(TransformVO data) { GameObject remotePlayer = Instantiate(tankPrefab, data.point, Quaternion.identity); remotePlayer.GetComponent <SpriteRenderer>().color = Color.red; PlayerRPC remoteRPC = remotePlayer.GetComponent <PlayerRPC>(); remoteRPC.SetRemote(); remoteRPC.SetTransform(data.point, data.rotation); return(remotePlayer); }