Skip to content

Instantly share code, notes, and snippets.

Created September 14, 2015 10:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/64d091c63cb41d345a19 to your computer and use it in GitHub Desktop.
Save anonymous/64d091c63cb41d345a19 to your computer and use it in GitHub Desktop.
Setting up Photon for Unity 5
using UnityEngine;
using System.Collections;
public class NetworkManager : Photon.MonoBehaviour {
private const string roomName = "RoomName";
private TypedLobby lobbyName = new TypedLobby("New_Lobby", LobbyType.Default);
private RoomInfo[] roomsList;
public GameObject player;
void Start () {
PhotonNetwork.ConnectUsingSettings("v4.2");
}
void Update () {
}
void OnGUI()
{
if (!PhotonNetwork.connected)
{
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
}
else if (PhotonNetwork.room == null)
{
// Create Room
if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server")) {
PhotonNetwork.CreateRoom(roomName, new RoomOptions() { maxPlayers = 2, isOpen = true, isVisible = true}, lobbyName);
}
// Join Room
if (roomsList != null) {
for (int i = 0; i < roomsList.Length; i++) {
if (GUI.Button(new Rect(100, 250 + (110 * i), 250, 100), "Join " + roomsList[i].name)) {
PhotonNetwork.JoinRoom(roomsList[i].name);
}
}
}
}
}
void OnConnectedToMaster() {
PhotonNetwork.JoinLobby(lobbyName);
}
void OnReceivedRoomListUpdate()
{
Debug.Log ("Room was created");
roomsList = PhotonNetwork.GetRoomList();
}
void OnJoinedLobby () {
Debug.Log ("Joined Lobby");
}
void OnJoinedRoom ()
{
Debug.Log("Connected to Room");
PhotonNetwork.Instantiate(player.name, Vector3.up * 5, Quaternion.identity, 0);
}
}
@ikrom
Copy link

ikrom commented Mar 30, 2016

thank you so much !

@GregHilston
Copy link

Any idea why OnJoinedRoom is not being called?

@abypaul
Copy link

abypaul commented Mar 21, 2019

error CS0246: The type or namespace name RoomInfo' could not be found. Are you missing Photon.Realtime' using directive?
Why This Error? Could You Please Give A Solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment