当玩家加入房间时,我想基于HashTable为其分配特定角色。但是,似乎似乎没有调用OnJoinedRoom,因为它没有出现Debug.Log。
我已经检查过我正在使用MonoBehaviourPunCallbacks。我正在使用Unity(个人版2019.1.0f2)和Photon 2
public class GameHandler : MonoBehaviourPunCallbacks
{
public readonly string[] ROLES = {
"Villager",
"Werewolf",
"Seer",
"Werewolf",
"Doctor",
"Villager"
};
Hashtable PlayerProperties = new Hashtable
{
{"Role", null},
{"Team", null}
};
public TMP_Text ROLE_TXT;
private void Start()
{
PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProperties);
}
public override void OnJoinedRoom()
{
Debug.Log("OnJoinedRoomCalled");
GetRoleAndTeam();
}
private void GetRoleAndTeam()
{
PlayerProperties["Role"] = ROLES[PhotonNetwork.CurrentRoom.PlayerCount - 1];
PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProperties);
string MyRole = (string) PhotonNetwork.LocalPlayer.CustomProperties["Role"];
Debug.Log("My Role :");
ROLE_TXT.text = MyRole;
if (MyRole.Equals("Werewolf"))
{
PlayerProperties["Team"] = "Werewolves";
PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProperties);
}
else
{
PlayerProperties["Team"] = "Villagers";
PhotonNetwork.LocalPlayer.SetCustomProperties(PlayerProperties);
}
}
}
我希望它调用OnJoinedRoom,因此它将运行调试日志以及GetRoleAndTeam(),但不会调用OnJoinedRoom
答案 0 :(得分:0)
设置
PhotonNetwork.AutomaticallySyncScene = false;
当您使用自动同步场景时,连接到已创建房间的玩家会立即开始加载 Master 拥有的场景并跳过 OnJoinedRoom 回调。