Create a gist now

Instantly share code, notes, and snippets.

anonymous /NetworkManager.cs
Created Sep 14, 2015

What would you like to do?
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

This comment has been minimized.

Show comment Hide comment
@ikrom

ikrom Mar 30, 2016

thank you so much !

ikrom commented Mar 30, 2016

thank you so much !

@GregHilston

This comment has been minimized.

Show comment Hide comment
@GregHilston

GregHilston Feb 7, 2018

Any idea why OnJoinedRoom is not being called?

Any idea why OnJoinedRoom is not being called?

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