创建房间没有重载方法错误

时间:2017-01-20 18:38:10

标签: c# unity3d photon

当我尝试使用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); 

2 个答案:

答案 0 :(得分:3)

这只是意味着您将错误的参数传递给CreateRoom函数。

根据光子documentationCreateRoom函数有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)

这些功能都不带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
}

答案 1 :(得分:0)

感谢您的回答我写了这段代码

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

人们可以加入游戏并观看房间内的最大玩家。再次感谢你,祝你好运。