Skip to content

Instantly share code, notes, and snippets.

@eelstork
Last active February 28, 2016 11:18
Show Gist options
  • Save eelstork/9eba6991cfdf813639e0 to your computer and use it in GitHub Desktop.
Save eelstork/9eba6991cfdf813639e0 to your computer and use it in GitHub Desktop.
A component that connects to Photon Unity Network and joins or creates a room.
using UnityEngine;
public class PUNNetworkController : MonoBehaviour {
void Start(){ PhotonNetwork.ConnectUsingSettings("v4.2"); }
void OnJoinLobby(){ StartGame (); }
void OnConnectedToMaster(){ StartGame (); }
void StartGame(){ PhotonNetwork.JoinRandomRoom(); }
void OnPhotonRandomJoinFailed(){ PhotonNetwork.CreateRoom("MyMatch"); }
void OnPhotonCreateGameFailed(){ Debug.LogError ("Create game failed"); }
void OnJoinedRoom(){ Debug.Log ("Room joined; ready to start the game"); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment