Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    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.