Question by
HackTheREALITY · Dec 23, 2017 at 02:13 PM ·
androidnetworkingmultiplayerphotonnetwork.connect
Unity - Photon OnJoinedRoom not being called
I am using photon to make a FPS game for android. Here is the code:
using UnityEngine;
using UnityEngine.UI;
public class SceneLoaderButton : Photon.PunBehaviour {
public string roomName, mapNameGL, password;
public GameObject loadingPan;
public MenuRooms menuManager;
// Use this for initialization
void Start () {
Button btn = GetComponent<Button> ();
btn.onClick.AddListener (ConnectCustomRoom);
}
// Update is called once per frame
void Update () {
}
void ConnectCustomRoom(){
string room = roomName;
RoomInfo[] ri;
ri = PhotonNetwork.GetRoomList ();
bool correct = false;
string passwd, mapName = "";
passwd = password;
foreach (RoomInfo info in ri) {
if (info.name == room) {
if (info.customProperties ["Password"].ToString() == passwd) {
print(info.playerCount + "/" + info.maxPlayers);
if (info.playerCount < info.maxPlayers)
{
correct = true;
}
else
{
menuManager.error("No room for you");
}
mapName = info.customProperties ["MapName"].ToString ();
}
else
{
menuManager.error("Incorrect password");
}
}
}
mapNameGL = mapName;
print(mapNameGL);
if (correct) {
print("Correct");
loadingPan.active = !loadingPan.active;
PhotonNetwork.playerName = "Player" + UnityEngine.Random.Range (1000,9999).ToString();
PhotonNetwork.JoinRoom(room);
}
}
void OnJoinedRoom()
{
print("Joined room: " + roomName);
//We joined room, load respective map
Application.LoadLevel(mapNameGL);
}
}
This is the code from button. It is instantiated and it should join the room, then load the scene. In other scripts, "onjoinedroom" callback works, even if I inherite from Photon.MonoBehaveiour, not from PUNBehaveiour. What is wrong?
Comment
Your answer
Follow this Question
Related Questions
How to add realtime game events without updating build? 1 Answer
Can i get names of some free LAN multiplayer assets?? 0 Answers
Unity Photon Player Instantiation 1 Answer
Unity Photon Handle Match Data 0 Answers
Photon ccu question 0 Answers