StatusCode: " + cause.ToString() + " ServerAddress: " + PhotonNetwork.ServerAddress) To know whether a connection to Photon was successful, we need to implement these callbacks: OnDisconnected(DisconnectCause cause), OnConnectedToMaster(), OnRoomListUpdate(List roomList) public override void OnDisconnected(DisconnectCause cause)ĭebug.Log("OnFailedToConnectToPhoton. We use the settings saved in PhotonServerSettings (a. PhotonNetwork.AutomaticallySyncScene = true This makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically This means as soon as the game opened, it connects to the Photon Server: // Use this for initialization Then we call ConnectUsingSettings() in the void Start(). Users are separated from each other by gameversion (which allows you to make breaking changes). Next, we create the necessary variables: //Our player name This step is necessary to be able to use Photon callbacks: public class PUN2_GameLobby : MonoBehaviourPunCallbacks Call it "_GameLobby" and assign the PUN2_GameLobby script to itįirst, we import the Photon namespaces by adding the lines below at the beginning of the script: using Photon.Pun Īlso before continuing, we need to replace default MonoBehaviour with MonoBehaviourPunCallbacks.
You can read more about Pricing Plans here
Import the PUN 2 package after Download is finished.Search for " PUN 2- Free" then click the first result or click here.Open your Unity project then go to the Asset Store: (Window -> General -> AssetStore) or press Ctrl+9.It contains all the scripts and files required for multiplayer integration. The first step is to download a PUN 2 package from the Asset Store. Unity version used in this tutorial: Unity 2018.3.0f2 (64-bit) Part 1: Setting up PUN 2 In this post we will be running through downloading the necessary files, setting up Photon AppID, and programming a simple multiplayer example. PUN 2 is the latest release of their API which has been greatly improved compared to the legacy version. One of such services is Photon Network, which we will be using for this tutorial. Nowadays there are numerous services that take care of server hosting. Unlike single-player games, multiplayer games require a remote server that plays the role of the bridge, allowing game clients to communicate with each other. Ever wondered what it takes to create a multiplayer game inside Unity?