创建房间失败。客户端位于MasterServer上

发布于 2025-01-09 15:39:08 字数 1625 浏览 4 评论 0原文

当我尝试创建房间时,没有任何反应,并且控制台中出现错误。我应该怎么办?

如果可以的话,写出具体应该替换的内容。

完整错误:

CreateRoom failed. Client is on MasterServer (must be Master Server for matchmaking)
    but not ready for operations (State: PeerCreated). Wait for callback: OnJoinedLobby or OnConnectedToMaster.

    UnityEngine.Debug:LogError (object)
    Photon.Pun.PhotonNetwork:CreateRoom (string,Photon.Realtime.RoomOptions,Photon.Realtime.TypedLobby,string[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1782)
    MenuManagerScript:CreateRoom () (at Assets/MenuManagerScript.cs:15)
    UnityEngine.EventSystems.EventSystem:Update () (at Library/PackageCache/[email protected]/Runtime/EventSystem/EventSystem.cs:385)

完整代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;

public class MenuManagerScript : MonoBehaviourPunCallbacks
{
    public InputField createInput;
    public InputField joinInput;
    public void CreateRoom() {
        RoomOptions roomOptions = new RoomOptions();
        roomOptions.MaxPlayers = 4;
        PhotonNetwork.CreateRoom(createInput.text, roomOptions);
    }
    public void JoinRoom() {
        PhotonNetwork.JoinRoom(joinInput.text);
    }
    public override void OnJoinedRoom() {
        PhotonNetwork.LoadLevel("Game");
    }
}

我从此视频获取代码

When I try to create a room, nothing happens and there is an error in the console. What should I do?

If it is possible, than write what specificly should be replaced.

Full error:

CreateRoom failed. Client is on MasterServer (must be Master Server for matchmaking)
    but not ready for operations (State: PeerCreated). Wait for callback: OnJoinedLobby or OnConnectedToMaster.

    UnityEngine.Debug:LogError (object)
    Photon.Pun.PhotonNetwork:CreateRoom (string,Photon.Realtime.RoomOptions,Photon.Realtime.TypedLobby,string[]) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1782)
    MenuManagerScript:CreateRoom () (at Assets/MenuManagerScript.cs:15)
    UnityEngine.EventSystems.EventSystem:Update () (at Library/PackageCache/[email protected]/Runtime/EventSystem/EventSystem.cs:385)

Full code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;

public class MenuManagerScript : MonoBehaviourPunCallbacks
{
    public InputField createInput;
    public InputField joinInput;
    public void CreateRoom() {
        RoomOptions roomOptions = new RoomOptions();
        roomOptions.MaxPlayers = 4;
        PhotonNetwork.CreateRoom(createInput.text, roomOptions);
    }
    public void JoinRoom() {
        PhotonNetwork.JoinRoom(joinInput.text);
    }
    public override void OnJoinedRoom() {
        PhotonNetwork.LoadLevel("Game");
    }
}

I took the code from this video

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

风追烟花雨 2025-01-16 15:39:08

这是我的光子网络代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class NetworkManager : MonoBehaviourPunCallbacks
{
    public static NetworkManager instance;

    public override void OnConnectedToMaster()
    {
        Debug.Log("Connected to master server");
        CreateRoom("testroom");
    }

    public override void OnCreatedRoom()
    {
        Debug.Log("Created room: " + PhotonNetwork.CurrentRoom.Name);
    }

    void Start()
    {
        Debug.Log(" started");
        PhotonNetwork.ConnectUsingSettings();
    }

    public void CreateRoom(string roomName)
    {
        PhotonNetwork.CreateRoom(roomName);
    }

    public void JoinRoom(string roomName)
    {
        PhotonNetwork.JoinRoom(roomName);
    }

    public void ChangeScene(string sceneName)
    {
        PhotonNetwork.LoadLevel(sceneName);
    }
}

Here is my code for photon network

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class NetworkManager : MonoBehaviourPunCallbacks
{
    public static NetworkManager instance;

    public override void OnConnectedToMaster()
    {
        Debug.Log("Connected to master server");
        CreateRoom("testroom");
    }

    public override void OnCreatedRoom()
    {
        Debug.Log("Created room: " + PhotonNetwork.CurrentRoom.Name);
    }

    void Start()
    {
        Debug.Log(" started");
        PhotonNetwork.ConnectUsingSettings();
    }

    public void CreateRoom(string roomName)
    {
        PhotonNetwork.CreateRoom(roomName);
    }

    public void JoinRoom(string roomName)
    {
        PhotonNetwork.JoinRoom(roomName);
    }

    public void ChangeScene(string sceneName)
    {
        PhotonNetwork.LoadLevel(sceneName);
    }
}
独自唱情﹋歌 2025-01-16 15:39:08

您想要在尝试创建或加入任何房间之前进行连接。
PUN 包含一个非常简单的脚本,可以让您轻松进入一个随机房间。查看 ConnectAndJoinRandom 组件。

You want to connect, before trying to create or join any rooms.
PUN contains a very simple script to get you into a random room without much hassle. Check out the ConnectAndJoinRandom component.

桃扇骨 2025-01-16 15:39:08

对我来说,问题是因为加载时默认场景是大厅,您需要在加载之前切换到加载场景,以便它可以正确连接到大厅,

基本上只需在玩之前切换到加载场景即可

For me the issue was because the default scene is Lobby when you load in, you need to switch to the Loading scene before you load so it can properly connect to Lobby

basically just switch to the Loading scene before you play

少年亿悲伤 2025-01-16 15:39:08

在编辑器中点击“播放”之前,您必须将场景更改为连接到服务器的场景,即具有 PhotonNetwork.ConnectUsingSettings() 函数的场景。

成功连接到服务器后,函数 createRoom() 应该可以工作。

Before you hit 'Play' in the editor, you must change your scene to the one that connects to your server, which is the scene with the function PhotonNetwork.ConnectUsingSettings().

After successfully connecting to the server, the function createRoom() should work.

难理解 2025-01-16 15:39:08

几个小时后,我意识到我的代码有一个问题:由于某种原因,当我尝试在大厅中将我的两个游戏连接在一起时,它出错了,在查看了很多帖子(其中没有任何帮助)后,我意识到我的两个游戏都连接到了不同的区域。这意味着这两个游戏无法连接,因此要解决此问题,您可以转到大厅代码并输入启动函数:PhotonNetwork.ConnectToRegion("your Region")
希望这对某人有帮助

After quite a few hours i realised a problem with my code, which was; for some reason when i tried to connect my two games together in the lobby it errored and after looking at a lot of posts, of which none helped, i realised that my two games had both connected to different regions. This meant that the two games couldn't connect, so to fix this problem you go to your lobby code and put in the start function: PhotonNetwork.ConnectToRegion("your region")
Hope this helps someone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文