问题描述
我有这样的场景: 加入大厅的第一个用户将在其屏幕上显示一个活动按钮。一些动作后,如果玩家点击按钮,它会被禁用,然后房间里的下一个玩家会激活这个按钮,依此类推。 基于属性“转动”,我想像这样更改此按钮状态。
在此函数 PassTurn
中,我首先将 LocalPlayer
的 Turn
属性设置为 false
,然后使用某种逻辑确定下一个玩家,并为该玩家设置将 Turn
属性设置为 true
。
private PassTurn()
{
PunHashtable _myCustomProperties_forCurrentPlayer = new PunHashtable();
_myCustomProperties_forCurrentPlayer["Turn"] = false;
PhotonNetwork.LocalPlayer.SetCustomProperties(_myCustomProperties_forCurrentPlayer);
foreach (Player player in PhotonNetwork.PlayerList)
{
// ... some logic to determine the next player to set the 'Turn' property to true
if (someCondition for player) {
PunHashtable _myCustomProperties_forNextPlayer = new PunHashtable();
_myCustomProperties_forNextPlayer["Turn"] = true;
player.SetCustomProperties(_myCustomProperties_forNextPlayer);
}
}
}
在 OnPlayerPropertiesUpdate
函数中,如果 Turn
属性发生变化,则根据 Turn
属性值激活或停用按钮(如果 true
- 显示按钮,如果 {{ 1}} 不显示按钮)。
false
这不能正常工作,因为它总是在 public override void OnPlayerPropertiesUpdate(Player targetPlayer,ExitGames.Client.Photon.Hashtable changedProps)
{
base.OnPlayerPropertiesUpdate(targetPlayer,changedProps);
if (targetPlayer != null) {
if (changedProps.ContainsKey("Turn"))
{
{
foreach (Player player in PhotonNetwork.PlayerList)
{
// this print will display (1,false) and (2,false) which is not correct,because the second player doesn't have de property changed
print(player.ActorNumber + player.CustomProperties["Turn"];
if ((bool)player.CustomProperties["Turn"] == true)
{
print("HEY HEY HEY 1");
endTurnBtn.SetActive(true);
}
if ((bool)player.CustomProperties["Turn"] == false)
{
print("HEY HEY HEY 2");
endTurnBtn.SetActive(false);
}
}
}
}
}
}
进入,当前播放的按钮将消失,但它永远不会出现在下一个播放器上。
对于这种情况,哪种方法是正确的?如何更改其他玩家屏幕上的 ui 组件?感谢您的时间!
稍后根据接受的评论进行编辑:
HEY HEY HEY 2.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)