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(); } } } }
Creating a room triggers the following callbacks:
OnCreatedRoom
, if the room is successfully created.OnPhotonCreateRoomFailed
, if...