Setting up Photon for Unity 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Any idea why OnJoinedRoom
is not being called?
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
thank you so much !