O'Reilly logo

Unity Multiplayer Games by Alan Stagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Random matchmaking

It's also possible to employ a form of random matchmaking. That is, by supplying the special room ID "$service-room$" to CreateJoinRoom, you will connect the user to so called "Service Rooms". A service room is a room with a randomly created ID, and a new room will only be created when the existing service rooms are all filled up to 75 percent (this gives some leeway to move users between rooms). By using CreateJoinRoom, the client will create a room if it doesn't exist, or join the existing one if it does.

void OnGUI()
{
  if( roomConnection != null )
    return;

  if( GUILayout.Button( "Join Random", GUILayout.Width( 200f ) ) )
  {
    client.Multiplayer.CreateJoinRoom( "$service-room$", "MyCode", true, null, null,
 delegate( Connection ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required