您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

35 行
1001 B

using UnityEngine;
using TMPro;
using Unity.Netcode;
namespace Unity.Multiplayer.Samples.BossRoom
{
/// <summary>
/// UI object that visually represents an object's name. Visuals are updated when NetworkVariable is modified.
/// </summary>
public class UIName : MonoBehaviour
{
[SerializeField]
TextMeshProUGUI m_UINameText;
NetworkVariable<FixedPlayerName> m_NetworkedNameTag;
public void Initialize(NetworkVariable<FixedPlayerName> networkedName)
{
m_NetworkedNameTag = networkedName;
m_UINameText.text = networkedName.Value.ToString();
networkedName.OnValueChanged += NameUpdated;
}
void NameUpdated(FixedPlayerName previousValue, FixedPlayerName newValue)
{
m_UINameText.text = newValue.ToString();
}
void OnDestroy()
{
m_NetworkedNameTag.OnValueChanged -= NameUpdated;
}
}
}