Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Unity Multiplayer After 10 Seconds Player Spawning in Unity Multiplayer

Discussion in 'Connected Games' started by siddharth3322, Oct 11, 2018.

  1. siddharth3322


    Nov 29, 2013
    I was using Unity's built-in multiplayer system for creating a multiplayer game and I have completed my whole game work.

    At present in my multiplayer game, my both players get spawned as the game get started but I want to spawn them after 10 seconds waiting.

    Because I want to provide this kind of functionality in a game so I want to give some time to players.


    For this reason, I have googled on multiple things and found this link:

    This way I can update the player and then attach with the network connection still two problems exist:

    • there was no way exist to give 10 seconds waiting because callback get called automatically - OnServerAddPlayer
    • OnServerAddPlayer method didn't get called automatically in a subclass of NetworkManager
    What do I require to do for these? Here is my NetworkManager code:

    Code (CSharp):
    1. public class DodgelsNetworkManager : NetworkManager
    2. {
    4. public override void OnClientConnect (NetworkConnection connection)
    5. {
    6.      base.OnClientConnect (connection);
    8.      GameHUDController.Instance.UpdateDebugMesssage ("\nOnClientConnect");
    10.      Camera.main.SendMessage (GameConstants.ACTIVATE_NETWORK_WAITING_PANEL, true, SendMessageOptions.DontRequireReceiver);
    11.      LayerScroller.stopScrolling = true;
    13.      // client joined the host
    14.      if (connection.connectionId > 0) {
    16.          StartCoroutine (AfterDelayHideWaitingDialog ());
    17.      }
    18. }
    20. IEnumerator AfterDelayHideWaitingDialog ()
    21. {
    22.      GameObject networkPlayerObj = null;
    23.      while (networkPlayerObj == null) {
    24.          yield return new WaitForSeconds (0.1f);
    25.          networkPlayerObj = GameObject.FindGameObjectWithTag (GameConstants.TAG_HUMAN_PLAYER);
    26.      }
    28.      networkPlayerObj.GetComponent<NetworkPlayerController> ().HidePlayerWaitingDialog ();
    29. }
    31. public override void OnServerAddPlayer (NetworkConnection conn, short playerControllerId)
    32. {
    33.      Debug.Log ("-------------OnServerAddPlayer");
    34.      GameObject player = Instantiate (playerPrefab, startPositions [conn.connectionId].position, Quaternion.identity);
    35.      NetworkServer.AddPlayerForConnection (conn, player, playerControllerId);
    36. }
    38. }
    Share your suggestions regarding this.