gpt4 book ai didi

c# - Unity3d错​​误CS0103 : The name `PeerState' does not exist in the current context

转载 作者:行者123 更新时间:2023-12-02 10:54:03 25 4
gpt4 key购买 nike

我收到此错误,我无法真正解决它,我不知道它要我做什么。
这是代码,如果您需要更多代码,请告诉我它们是否可以帮助您解决。

using System;
using UnityEngine;
using Random = UnityEngine.Random;


public class LobbyMenu : MonoBehaviour
{
//private string[]FirstName = new string[7]{"Clever", "Cunning", "Wise", "Awesome", "Amazing", "Dark", "Heroic"};
//private string[]LastName = new string[7]{"Rogue", "Wizard", "Mage", "Summoner", "Warrior", "Assassin", "Ranger"};
private string roomName = "myRoom";
private bool MessageRoomNameTaken = false;
private float MessageRoomTakenTimeToDisplay = 0;
private Vector2 scrollPos = Vector2.zero;

private bool connectFailed = false;

public static readonly string SceneNameMenu = "LobbyScene";

public static readonly string SceneNameGame = "GameScene";

public void Awake()
{
// 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;

// the following line checks if this client was just created (and not yet online). if so, we connect
if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated)
{
// Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project)
PhotonNetwork.ConnectUsingSettings("1.0");
}

// generate a name for this player, if none is assigned yet
if (String.IsNullOrEmpty(PhotonNetwork.playerName))
{
//PhotonNetwork.playerName = "Guest" + Random.Range(1, 9999);
//PhotonNetwork.playerName = FirstName[Random.Range(0, 6)] + " " + LastName[Random.Range(0, 6)];
PhotonNetwork.playerName = MainMenu.username;
}

// if you wanted more debug out, turn this on:
// PhotonNetwork.logLevel = NetworkLogLevel.Full;
}

public void OnGUI()
{
if (!PhotonNetwork.connected)
{
if (PhotonNetwork.connecting)
{
GUILayout.Label("Connecting to: " + PhotonNetwork.ServerAddress);
}
else
{
GUILayout.Label("Not connected. Check console output. Detailed connection state: " + PhotonNetwork.connectionStateDetailed + " Server: " + PhotonNetwork.ServerAddress);
}

if (this.connectFailed)
{
GUILayout.Label("Connection failed. Check setup and use Setup Wizard to fix configuration.");
GUILayout.Label(String.Format("Server: {0}", new object[] {PhotonNetwork.ServerAddress}));
GUILayout.Label("AppId: " + PhotonNetwork.PhotonServerSettings.AppID);

if (GUILayout.Button("Try Again", GUILayout.Width(100)))
{
this.connectFailed = false;
PhotonNetwork.ConnectUsingSettings("1.0");
}
}

return;
}




GUI.skin.box.fontStyle = FontStyle.Bold;
GUI.Box(new Rect((Screen.width - 400) / 2, (Screen.height - 350) / 2, 400, 300), "Join or Create a Room");
GUILayout.BeginArea(new Rect((Screen.width - 400) / 2, (Screen.height - 350) / 2, 400, 300));

GUILayout.Space(25);

// Player name
GUILayout.BeginHorizontal();
GUILayout.Label("Player name:", GUILayout.Width(100));
GUILayout.Label(PhotonNetwork.playerName);
//PhotonNetwork.playerName = GUILayout.TextField(PhotonNetwork.playerName);
GUILayout.Space(105);
if (GUI.changed)
{
// Save name
PlayerPrefs.SetString("playerName", PhotonNetwork.playerName);
}
GUILayout.EndHorizontal();

GUILayout.Space(15);

// Join room by title
GUILayout.BeginHorizontal();
GUILayout.Label("Roomname:", GUILayout.Width(100));
this.roomName = GUILayout.TextField(this.roomName);

if (GUILayout.Button("Create Room", GUILayout.Width(100)))
{

foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
{
if (roomInfo.name == this.roomName) {MessageRoomNameTaken = true; break;}

}
if (MessageRoomNameTaken==false) PhotonNetwork.CreateRoom(this.roomName, new RoomOptions() { maxPlayers = 2 }, null);

Debug.Log("OnJoinedRoom");

}



GUILayout.EndHorizontal();

// Create a room (fails if exist!)
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
//this.roomName = GUILayout.TextField(this.roomName);
if (GUILayout.Button("Join Room", GUILayout.Width(100)))
{
PhotonNetwork.JoinRoom(this.roomName);
}

GUILayout.EndHorizontal();


GUILayout.Space(15);

// Join random room
GUILayout.BeginHorizontal();

GUILayout.Label(PhotonNetwork.countOfPlayers + " users are online in " + PhotonNetwork.countOfRooms + " rooms.");
GUILayout.FlexibleSpace();
if (GUILayout.Button("Join Random", GUILayout.Width(100)))
{
PhotonNetwork.JoinRandomRoom();
}


GUILayout.EndHorizontal();

GUILayout.Space(15);
if (PhotonNetwork.GetRoomList().Length == 0)
{
GUILayout.Label("Currently no games are available.");
GUILayout.Label("Rooms will be listed here, when they become available.");
}
else
{
int roomcount = PhotonNetwork.GetRoomList().Length;
if (roomcount==1 )GUILayout.Label("1 room is currently available:");
else GUILayout.Label(PhotonNetwork.GetRoomList().Length + " rooms are currently available:");
// Room listing: simply call GetRoomList: no need to fetch/poll whatever!
this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
{
GUILayout.BeginHorizontal();
GUILayout.Label(roomInfo.name + " " + roomInfo.playerCount + "/" + roomInfo.maxPlayers);
if (GUILayout.Button("Join"))
{
PhotonNetwork.JoinRoom(roomInfo.name);

}

GUILayout.EndHorizontal();
}

GUILayout.EndScrollView();
}

GUILayout.EndArea();

if (MessageRoomNameTaken == true) {

MessageRoomTakenTimeToDisplay = 5; // we will display the warning for this number of seconds
MessageRoomNameTaken = false;
}
if (MessageRoomTakenTimeToDisplay >0 ) { GUI.contentColor = Color.red;
GUI.Label(new Rect(400,50,300,60), "The room with this name already exists");
MessageRoomTakenTimeToDisplay = MessageRoomTakenTimeToDisplay - Time.deltaTime;
}
}

// We have two options here: we either joined(by title, list or random) or created a room.
public void OnJoinedRoom()
{

Debug.Log("OnJoinedRoom");

}

public void OnCreatedRoom()
{
Debug.Log("OnCreatedRoom");
PhotonNetwork.LoadLevel(SceneNameGame);
}

public void OnDisconnectedFromPhoton()
{
Debug.Log("Disconnected from Photon.");
}

public void OnFailedToConnectToPhoton(object parameters)
{
this.connectFailed = true;
Debug.Log("OnFailedToConnectToPhoton. StatusCode: " + parameters + " ServerAddress: " + PhotonNetwork.networkingPeer.ServerAddress);
}
}

我用光子网络是的。所以请重写或修复它或至少告诉我我不知道该怎么做。
// the following line checks if this client was just created (and not yet online). if so, we connect
if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated)
{
// Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project)
PhotonNetwork.ConnectUsingSettings("1.0");
}

最佳答案

如果您检查PhotonNetwork的文档,您会看到PhotonNetwork.connectionStateDetailed静态属性返回ClientState枚举值(而不是PeerState)。

来源: https://doc-api.photonengine.com/en/pun/current/class_photon_network.html

这是enum文档:Enum Documentation

因此,更改:

if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated)


if (PhotonNetwork.connectionStateDetailed == ClientState.PeerCreated)

关于c# - Unity3d错​​误CS0103 : The name `PeerState' does not exist in the current context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43783772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com