Navigation

    FLOBUK Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Search

    SOLVED Player not spawning if joined before scene load

    Tanks Multiplayer
    1
    2
    16
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      habeeb22 last edited by Baron

      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 NetworkManagerCustom

      OnPlayerEnteredRoom(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

      H 1 Reply Last reply Reply Quote 0
      • H
        habeeb22 @habeeb22 last edited by

        @habeeb22
        solved
        in GameManager

        private 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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post