using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace cc.ivanli.pun01
{
public class PlayerUI : MonoBehaviour
{
[Tooltip("UI Text to display Player's Name")]
[SerializeField]
private TMP_Text playerNameText;
[Tooltip("UI Slider to display Player's Health")]
[SerializeField]
private Slider playerHealthSlider;
private PlayerManager target;
public void SetTarget(PlayerManager _target)
{
if (_target == null)
{
Debug.LogError("Missing PlayMakerManager target for PlayerUI.SetTarget.", this);
return;
}
// Cache references for efficiency
target = _target;
if (playerNameText != null)
{
playerNameText.text = target.photonView.Owner.NickName;
}
}
void Awake()
{
this.transform.SetParent(GameObject.Find("Canvas").GetComponent(), false);
}
void Update()
{
if (target == null)
{
Destroy(gameObject);
return;
}
// Reflect the Player Health
if (playerHealthSlider != null)
{
playerHealthSlider.value = target.Health;
}
}
}
}