[英]Why PUN is not giving callbacks? ProtonNetworking is not working as expected
i am trying to make simple steps with PUN, just connect to master server, and join random room. 我正在尝试通过PUN进行简单的操作,只需连接到主服务器,然后加入随机房间即可。 I have setted log all info to console, and as I understand I am connectin to server, but OnConnectedToMaster is never called.
我已将所有信息设置为登录到控制台,据我了解,我已连接到服务器,但从未调用过OnConnectedToMaster。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
public class RandomMatchmakera : Photon.PunBehaviour {
/// <summary>
/// MonoBehaviour method called on GameObject by Unity during early initialization phase.
/// </summary>
void Avake(){
// this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically
PhotonNetwork.automaticallySyncScene = true;
}
void Start(){
// the following line checks if this client was just created (and not yet online). if so, we connect
if (PhotonNetwork.connectionStateDetailed == ClientState.PeerCreated)
{
Debug.Log ("connecting");
// Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project)
PhotonNetwork.ConnectUsingSettings("0.9");
}
}
public void OnJoinedLobby()
{
Debug.Log("DemoAnimator/Launcher: OnJoinedLobby() was called by PUN");
PhotonNetwork.JoinRandomRoom();
}
public override void OnConnectedToMaster()
{
Debug.Log("DemoAnimator/Launcher: OnConnectedToMaster() was called by PUN");
PhotonNetwork.JoinRandomRoom();
}
public override void OnDisconnectedFromPhoton()
{
Debug.LogWarning("DemoAnimator/Launcher: OnDisconnectedFromPhoton() was called by PUN");
}
public override void OnPhotonRandomJoinFailed(object[] codeAndMsg){
Debug.LogWarning("DemoAnimator/Launcher: Failing joining random room");
PhotonNetwork.CreateRoom (null, new RoomOptions (){ MaxPlayers = 4 }, null);
}
public override void OnJoinedRoom(){
Debug.LogWarning("DemoAnimator/Launcher: Joined room");
}
public void OnFailedToConnectToPhoton(object parameters)
{
Debug.Log("OnFailedToConnectToPhoton. StatusCode: " + parameters + " ServerAddress: " + PhotonNetwork.ServerAddress);
}
}
Here are going loggs. 这里是loggs。
I have just copy pasted your solution and it is successfully being called.Assuming you are using PhotonTutorials from PUN asset and Marco Polo example I think you have not referenced RandomMatchmakera script from your project. 我刚刚复制粘贴了您的解决方案,并成功调用了它。假设您使用的是来自PUN资产的PhotonTutorials和Marco Polo示例,我认为您没有从项目中引用RandomMatchmakera脚本。
I hope this will help someone. 我希望这会对某人有所帮助。 For me the problem was with my region.
对我来说,问题出在我所在的地区。 I had selected my region to none instead of specifying it to a particular region.
我没有选择任何区域,而没有将其指定为特定区域。 Therefore locate the
因此找到
PhotonServerSettings
PhotonServerSettings
file and change the region to something specific eg EU, Kr etc 归档并将区域更改为特定的内容,例如EU,Kr等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.