C# Unity网络大厅:设置玩家名称
我在我的2D游戏的网络大厅工作,我对我的玩家的名字有点问题: 我下载来帮助我 但正如你所见,当你加入游戏并进入大厅时,玩家的名字可以更改 但是在我的项目中,我想写下我的名字,点击Valid,然后连接到大厅。就像这样: 我的问题是,我不知道如何使用我的输入字段文本作为大厅中播放器的名称 我试图用static属性将名称保存在一个静态类中,但每个玩家都有相同的名称 这是我的代码:C# Unity网络大厅:设置玩家名称,c#,networking,unity3d,C#,Networking,Unity3d,我在我的2D游戏的网络大厅工作,我对我的玩家的名字有点问题: 我下载来帮助我 但正如你所见,当你加入游戏并进入大厅时,玩家的名字可以更改 但是在我的项目中,我想写下我的名字,点击Valid,然后连接到大厅。就像这样: 我的问题是,我不知道如何使用我的输入字段文本作为大厅中播放器的名称 我试图用static属性将名称保存在一个静态类中,但每个玩家都有相同的名称 这是我的代码: //Attached to my Name Panel public class LobbyName : MonoBeh
//Attached to my Name Panel
public class LobbyName : MonoBehaviour
{
public LobbyManager LobbyManager;
public Text TxtName;
public void OnClickValidName()
{
Constants.PlayerName = TxtName.text;
LobbyManager.ChangeTo(LobbyManager.MenuLobby);
}
}
//Attached to my canvas
public class LobbyManager : NetworkLobbyManager
{
public Button BackButton;
private RectTransform _currentPanel;
public RectTransform ListLobby;
public RectTransform MenuLobby;
public RectTransform NameLobby;
public string PlayerName { get; set; }
private void Start()
{
_currentPanel = NameLobby;
NameLobby.gameObject.SetActive(true);
}
public void ChangeTo(RectTransform newPanel)
{
if (_currentPanel != null)
_currentPanel.gameObject.SetActive(false);
if (newPanel != null)
newPanel.gameObject.SetActive(true);
_currentPanel = newPanel;
}
}
//Attached to my Player Item
public class LobbyPlayer : NetworkLobbyPlayer
{
public Text TxtPlayerName;
public string PlayerName = "";
public override void OnClientEnterLobby()
{
base.OnClientEnterLobby();
TxtPlayerName.text = Constants.PlayerName;
LobbyPlayerList.Instance.AddPlayer(this);
}
}
//Attached to my Menu lobby panel
public class LobbyMenu : MonoBehaviour
{
public LobbyManager LobbyManager;
public void OnClickConnect()
{
LobbyManager.StartClient();
LobbyManager.ChangeTo(LobbyManager.ListLobby);
}
}
我知道我的静态类不工作,因为我只有一个实例
(在资产示例中,可以在大厅面板中更改playerName,但我不需要相同的配置)
你能帮我吗
谢谢看看NetworkIdentity-localPlayerAuthority。嘿,Sajmoon,谢谢你的回复。我用PlayerPrefs解决了我的答案。我知道这不是一个好的解决方案,但我的球员已经有了相同的名字,如果他离开的话。你能和我分享一个名为property plz的例子吗?