0
我有一個與Unity的多人遊戲。作爲主機(汽車命名NiciBozz)它看起來像這樣: Unity用戶名不顯示
這是好的,但作爲一個客戶端(這裏命名NiciBot)它看起來像這樣:
相關的用戶名的代碼:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
[NetworkSettings(channel = 1, sendInterval = 0.2f)]
public class PlayerControll : NetworkBehaviour
{
public Text Name;
[SyncVar]
public string playerName;
private void Start()
{
if (isLocalPlayer)
{
CmdChangeName(PlayerPrefs.GetString("Name"));
}
}
[Command(channel =1)]
private void CmdChangeName(string name)
{
if (!isLocalPlayer)
{
Name.text = name;
playerName = name;
SetDirtyBit(1);
return;
}
Name.text = name;
playerName = name;
SetDirtyBit(1);
}
}
我該怎麼做才能正確同步用戶名?
不可以,但它不會因爲內容是相同的任何改變。 – NiciBozz
那麼這個「ASDFASDF」如何顯示在汽車之上? –
它是ui.text元素的默認文本 – NiciBozz