我正在尝试交换玩家姓名,以便两个玩家都可以轻松地在每个屏幕上识别,但是目前正在发生这种情况,请检查下图:
您可以清楚地看到名称没有转移。这种代码,我已经使用并进行了多次测试:
void Start ()
{
spriteRenderer = GetComponent<SpriteRenderer> ();
circleCollder = GetComponent<CircleCollider2D> ();
// StartCoroutine (ColorSwitcher ());
InitialTasks ();
}
private void InitialTasks ()
{
isAlive = true;
GameManager.Instance.IsPlayerWin = false;
int selectedTheme = Random.Range (0, ballSprites.Length);
spriteRenderer.sprite = ballSprites [selectedTheme];
trailRenderer.material = trailMaterials [selectedTheme];
destroyParticleObj.GetComponent<ParticleSystemRenderer> ().material = trailMaterials [selectedTheme];
hidePlayerName += OnTouchHidePlayerName;
if (!isLocalPlayer) {
// remote player
gameObject.tag = GameConstants.TAG_REMOTE_PLAYER;
} else {
// local player
// Debug.Log ("locally set player name: " + DataCollection.localPlayer.PlayerName);
playerNameText.text = DataCollection.localPlayer.PlayerName;
}
if (isServer)
RpcSetRemotePlayerName (DataCollection.localPlayer.PlayerName);
// else
// CmdSetRemotePlayerName (DataCollection.localPlayer.PlayerName);
}
[ClientRpc]
private void RpcSetRemotePlayerName (string remotePlayerName)
{
playerNameText.text = remotePlayerName + "@";
Debug.Log ("rpc remote player name: " + remotePlayerName);
}
[Command]
private void CmdSetRemotePlayerName (string remotePlayerName)
{
if (!isLocalPlayer) {
playerNameText.text = remotePlayerName + "#";
Debug.Log ("cmd remote player name: " + remotePlayerName);
}
}
基本上,我想在2人多人游戏中交换两个人的名字。所以请给我一些建议。