创建房间没有重载方法错误
Create Room No overloaded Method Error
我尝试使用 PhotonNetwork.CreateRoom()
函数时出现错误。我正在尝试向它传递 6 个参数。
我的Unity版本是4.7.2,这个功能来自光子云插件。
CheckPlayerNameAndRoom();
PhotonNetwork.player.name = playerName;
Hashtable setMapName = new Hashtable();
setMapName["MapName"] = allMaps[selectedMap].mapName;
setMapName["RoundDuration"] = roundDuration;
setMapName["GameMode"] = gameMode;
string[] exposedProps = new string[3];
exposedProps[0] = "MapName";
exposedProps[1] = "RoundDuration";
exposedProps[2] = "GameMode";
//Create new Room
PhotonNetwork.CreateRoom(newRoomName, true, true, maxPlayers, setMapName, exposedProps);
这只是意味着您向 CreateRoom 函数传递了错误的参数。
根据 photons documentation,CreateRoom
函数有 3 个重载。
static bool CreateRoom (string roomName)
static bool CreateRoom (string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
static bool CreateRoom (string roomName, RoomOptions roomOptions, TypedLobby typedLobby, string[] expectedUsers)
None 这些函数采用 bool 或 6 个参数。遇到此类问题时请务必查看文档。
下面是有关如何使用每个方法重载的示例。
string newRoomName = "AloneWolf";
if(CreateRoom (newRoomName))
{
//Success
}
或
string newRoomName = "AloneWolf";
RoomOptions roomOptions = new RoomOptions();
TypedLobby typedLobby = new TypedLobby ();
if(CreateRoom (newRoomName, roomOptions, typedLobby))
{
//Success
}
或
string newRoomName = "AloneWolf";
RoomOptions roomOptions = new RoomOptions();
TypedLobby typedLobby = new TypedLobby ();
string[] expectedUsers = { "AloneWolf","OtherUsers"};
if(CreateRoom (newRoomName, roomOptions, typedLobby, expectedUsers))
{
//Success
}
感谢您的回答我写了这段代码
Hashtable roomProps = new Hashtable() { { "MapName", allMaps[selectedMap].mapName }, { "RoundDuration", roundDuration },{ "GameMode", gameMode } };
string[] roomPropsInLobby = { "MapName", "RoundDuration" ,"GameMode" };
RoomOptions roomOptions = new RoomOptions();
roomOptions.customRoomProperties = roomProps;
roomOptions.customRoomPropertiesForLobby = roomPropsInLobby;
roomOptions.isVisible = true;
roomOptions.maxPlayers = (byte)maxPlayers;
PhotonNetwork.CreateRoom(newRoomName,roomOptions,TypedLobby.Default);
人们可以加入游戏并查看房间中的最大玩家数。再次感谢你,祝你好运。
我尝试使用 PhotonNetwork.CreateRoom()
函数时出现错误。我正在尝试向它传递 6 个参数。
我的Unity版本是4.7.2,这个功能来自光子云插件。
CheckPlayerNameAndRoom();
PhotonNetwork.player.name = playerName;
Hashtable setMapName = new Hashtable();
setMapName["MapName"] = allMaps[selectedMap].mapName;
setMapName["RoundDuration"] = roundDuration;
setMapName["GameMode"] = gameMode;
string[] exposedProps = new string[3];
exposedProps[0] = "MapName";
exposedProps[1] = "RoundDuration";
exposedProps[2] = "GameMode";
//Create new Room
PhotonNetwork.CreateRoom(newRoomName, true, true, maxPlayers, setMapName, exposedProps);
这只是意味着您向 CreateRoom 函数传递了错误的参数。
根据 photons documentation,CreateRoom
函数有 3 个重载。
static bool CreateRoom (string roomName)
static bool CreateRoom (string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
static bool CreateRoom (string roomName, RoomOptions roomOptions, TypedLobby typedLobby, string[] expectedUsers)
None 这些函数采用 bool 或 6 个参数。遇到此类问题时请务必查看文档。
下面是有关如何使用每个方法重载的示例。
string newRoomName = "AloneWolf";
if(CreateRoom (newRoomName))
{
//Success
}
或
string newRoomName = "AloneWolf";
RoomOptions roomOptions = new RoomOptions();
TypedLobby typedLobby = new TypedLobby ();
if(CreateRoom (newRoomName, roomOptions, typedLobby))
{
//Success
}
或
string newRoomName = "AloneWolf";
RoomOptions roomOptions = new RoomOptions();
TypedLobby typedLobby = new TypedLobby ();
string[] expectedUsers = { "AloneWolf","OtherUsers"};
if(CreateRoom (newRoomName, roomOptions, typedLobby, expectedUsers))
{
//Success
}
感谢您的回答我写了这段代码
Hashtable roomProps = new Hashtable() { { "MapName", allMaps[selectedMap].mapName }, { "RoundDuration", roundDuration },{ "GameMode", gameMode } };
string[] roomPropsInLobby = { "MapName", "RoundDuration" ,"GameMode" };
RoomOptions roomOptions = new RoomOptions();
roomOptions.customRoomProperties = roomProps;
roomOptions.customRoomPropertiesForLobby = roomPropsInLobby;
roomOptions.isVisible = true;
roomOptions.maxPlayers = (byte)maxPlayers;
PhotonNetwork.CreateRoom(newRoomName,roomOptions,TypedLobby.Default);
人们可以加入游戏并查看房间中的最大玩家数。再次感谢你,祝你好运。