简体   繁体   中英

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. I have setted log all info to console, and as I understand I am connectin to server, but OnConnectedToMaster is never called.

 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.

Firstlog

Secondlog

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. 这是你的做法

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

file and change the region to something specific eg EU, Kr etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM