Unity - Photon OnJoinedRoom 未被调用
Unity - Photon OnJoinedRoom not being called
我正在使用 photon 为 android 制作 FPS 游戏。
这是代码:
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);
}
}
这是来自按钮的代码。它被实例化并且应该加入房间,然后加载场景。在其他脚本中,"onjoinedroom" 回调有效,即使我继承自 Photon.MonoBehaveiour,而不是 PUNBehaveiour。怎么了?
根据 PUN 文档,它是一个虚拟成员,因此您可以覆盖该方法。
尝试将方法更改为:
override void OnJoinedRoom ()
{
//your codes
}
//or
public override void OnJoinedRoom ()
{
//your codes
}
This class provides a .photonView and all callbacks/events that PUN
can call. Override the events/methods you want to use. By extending
this class, you can implement individual methods as override.
希望对你有所帮助。
我正在使用 photon 为 android 制作 FPS 游戏。 这是代码:
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);
}
}
这是来自按钮的代码。它被实例化并且应该加入房间,然后加载场景。在其他脚本中,"onjoinedroom" 回调有效,即使我继承自 Photon.MonoBehaveiour,而不是 PUNBehaveiour。怎么了?
根据 PUN 文档,它是一个虚拟成员,因此您可以覆盖该方法。
尝试将方法更改为:
override void OnJoinedRoom ()
{
//your codes
}
//or
public override void OnJoinedRoom ()
{
//your codes
}
This class provides a .photonView and all callbacks/events that PUN can call. Override the events/methods you want to use. By extending this class, you can implement individual methods as override.
希望对你有所帮助。