SOLVED Player not spawning if joined before scene load
-
Hi
Thank you for your great asset.
I have some problem and need your help please.- after I creating room waiting 30 second and than close this room and load the scene (player can join this room within 30 second only after that it will close )
if (!PhotonNetwork.IsMasterClient) return; if (!startTimer) return; timerIncrementValue = PhotonNetwork.Time - startTime; if (timerIncrementValue >= timer) { //Timer Completed //Do What Ever You What to Do Here PhotonNetwork.CurrentRoom.IsOpen = false; PhotonNetwork.CurrentRoom.IsVisible = false; PhotonNetwork.LoadLevel(onlineSceneIndex); startTimer = false; }
but after the scene loaded master only spawning his player other player not spawning
what I did
in NetworkManagerCustomOnPlayerEnteredRoom(Photon.Realtime.Player player) { //only let the master client handle this connection if (!PhotonNetwork.IsMasterClient) return; //get the next team index which the player should belong to //assign it to the player and update player properties int teamIndex = /*GameManager.GetInstance().*/GetTeamFill(); PhotonNetwork.CurrentRoom.AddSize(teamIndex, +1); player.SetTeam(teamIndex); //also player properties are not cleared when disconnecting and connecting //automatically, so we have to set all existing properties to null //these default values will get overriden by correct data soon player.Clear(); //the master client sends an instruction to this player for adding him to the game //this.photonView.RPC("AddPlayer", player); } public void AddPlayer()
in GameManager
private void Start() { NetworkManagerCustom.GetInstance().AddPlayer(); }
after these changes all player spawned but only master not correctly spawning in different color and wrong position.
Kindly need your support.
And thank you so much in advance.
Habib -
@habeeb22
solved
in GameManagerprivate void Start() { if (PhotonNetwork.IsMasterClient) { NetworkManagerCustom.GetInstance().addPlayerthis(); } }
in NetworkManagerCustom
public void addPlayerthis() { foreach (var playerrr in PhotonNetwork.PlayerList) //loop through each player and spawn a player { this.photonView.RPC("AddPlayer", playerrr); } public override void OnJoinedRoom() { //we've joined a finished room, disconnect immediately if (GameManager.GetInstance() != null && GameManager.GetInstance().IsGameOver()) { PhotonNetwork.Disconnect(); return; } if (!PhotonNetwork.IsMasterClient) return; //add ourselves to the game. This is only called for the master client //because other clients will trigger the OnPhotonPlayerConnected callback directly //StartCoroutine(WaitForSceneChange()); addMyself(); } void addMyself() { //I connected My selve OnPlayerEnteredRoom(PhotonNetwork.LocalPlayer); }
hope it will help if any one needed
Thanks
Habib