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

Creating and joining rooms

Let us have a look at how to create rooms.

Creating rooms

To create a room in PUN, use the CreateRoom function:

using UnityEngine; using System.Collections; public class Example_CreateRoom : MonoBehaviour { void OnGUI() { // if we're not inside a room, let the player create a room if( PhotonNetwork.room == null ) { // if create room button clicked { // create a room called "RoomNameHere", visible to the lobby, allows other players to join, and allows up to 8 players PhotonNetwork.CreateRoom( "RoomNameHere", true, true, 8 ); } } else { // we're connected to a room, display some info such as room name, player count, etc. // disconnect from the current room // if disconnect button clicked { PhotonNetwork.LeaveRoom(); } } } ...

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