Connecting from Unity and passing messages
Connecting to a Photon Server from Unity is very simple. You just need to specify the IP, port, and application which you want to use (in this case, we will specify PhotonAckServer
as the application). Each application defined in the Photon Server configuration will run alongside each other—this lets you run a number of different server types such as master servers and game servers on a single physical machine.
Let's create a script to connect to Photon, service the connection ten times per second, and sends a test message to the server (which responds with an acknowledgement message).
First, we'll start with this:
using UnityEngine; using System.Collections; using ExitGames.Client.Photon; public class PhotonAckClient : MonoBehaviour, IPhotonPeerListener { }
We'll add some variables to the top of the script:
public PhotonPeer peer; private bool connected = false;
In Start, we'll connect to the server and kick off a co-routine...