• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dudedude123 · Sep 21, 2015 at 09:52 AM · c#networkinglobby

setting up the lobby

I have made a script for the lobby.

 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.Networking.Types;
 using UnityEngine.Networking.Match;
 using System.Collections.Generic;
 
 public class HostGame : MonoBehaviour
 {
     List<MatchDesc> matchList = new List<MatchDesc>();
     bool matchCreated;
     NetworkMatch networkMatch;
 
     void Awake()
     {
         networkMatch = gameObject.AddComponent<NetworkMatch>();
     }
 
     public void CreateRooms()
     {
         CreateMatchRequest create = new CreateMatchRequest();
         create.name = "NewRoom";
         create.size = 2;
         create.advertise = true;
         create.password = "";
 
         networkMatch.CreateMatch(create, OnMatchCreate);
     }
 
     public void ListRooms()
     {
         networkMatch.ListMatches(0, 20, "", OnMatchList);
     }
 
     void OnGUI()
     {
 
 
 
 
         if (matchList.Count > 0)
         {
             GUILayout.Label("Current rooms");
         }
         foreach (var match in matchList)
         {
             if (GUILayout.Button(match.name))
             {
                 networkMatch.JoinMatch(match.networkId, "", OnMatchJoined);
             }
         }
     }
 
     public void OnMatchCreate(CreateMatchResponse matchResponse)
     {
         if (matchResponse.success)
         {
             Debug.Log("Create match succeeded");
             matchCreated = true;
             Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));
             NetworkServer.Listen(new MatchInfo(matchResponse), 9000);
         }
         else
         {
             Debug.LogError("Create match failed");
         }
     }
 
     public void OnMatchList(ListMatchResponse matchListResponse)
     {
         if (matchListResponse.success && matchListResponse.matches != null)
         {
             networkMatch.JoinMatch(matchListResponse.matches[0].networkId, "", OnMatchJoined);
         }
     }
 
     public void OnMatchJoined(JoinMatchResponse matchJoin)
     {
         if (matchJoin.success)
         {
             Debug.Log("Join match succeeded");
             if (matchCreated)
             {
                 Debug.LogWarning("Match already set up, aborting...");
                 return;
             }
             Utility.SetAccessTokenForNetwork(matchJoin.networkId, new NetworkAccessToken(matchJoin.accessTokenString));
             NetworkClient myClient = new NetworkClient();
             myClient.RegisterHandler(MsgType.Connect, OnConnected);
             myClient.Connect(new MatchInfo(matchJoin));
         }
         else
         {
             Debug.LogError("Join match failed");
         }
     }
 
    public void OnConnected(NetworkMessage msg)
 {
     Debug.Log("Connected!");
     Application.LoadLevel("Game");
 }
 }
 
 

I want to use this code to load the level

 public void OnConnected(NetworkMessage msg)
     {
         Debug.Log("Connected!");
         Application.LoadLevel("Game");
     }

Is this the right code to load the multiplayer level?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Unet NetworkLobbyManager - Intercept scene loading to do fading/scene transition 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

UNET Display Connected Player Names inGame UI 0 Answers

UNET Multiplayer Lobby not creating an instance of the lobby player 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges