2017-03-18 167 views
0

我想用PUN做簡單的步驟,只需連接到主服務器,並加入隨機房間。 我已經設置日誌所有信息到控制檯,並據我所知我連接到服務器,但OnConnectedToMaster從未被調用。爲什麼PUN不回撥? ProtonNetworking沒有按預期工作

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); 
} 
} 

這裏有loggs。

Firstlog

Secondlog

+0

如果我沒有弄錯PhotonNetwork.ConnectUsingSettings()將在您自己託管Photon時使用。編輯:它看起來像你成功地通過操作230(認證),並從服務器收到您的唯一ID。此外,你也訪問了GameServer。我沒有看到問題 –

+0

正如我從文檔中所瞭解的這個功能連接到光子云,如果你想Connetc自己的主機,你必須使用ConnectToMaster() 問題是我沒有得到回調OnConnectedToMaster – jokermanx

+0

請你刪除if (PhotonNetwork.connectionStateDetailed == ClientState.PeerCreated)並再試一次 –

回答

0

我剛纔複製粘貼您的解決方案,併成功地被called.Assuming您使用PhotonTutorials從潘資產和馬可波羅的例子,我覺得你沒有引用RandomMatchmakera從您的腳本項目。 Here is how you do it

相關問題