Bomberman/Assets/Scripts/PlayerLabel.cs

31 lines
731 B
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PlayerLabel : MonoBehaviour {
[HideInInspector]
public Transform player;
public TextMeshProUGUI playerName;
public TextMeshProUGUI controller;
RectTransform rectTransform;
new Camera camera;
void Awake() {
camera = Camera.main;
rectTransform = GetComponent<RectTransform>();
playerName = GetComponentInChildren<TextMeshProUGUI>();
}
void LateUpdate() {
if (!player) return;
rectTransform.position = camera.WorldToScreenPoint(player.position + 1.5f * Vector3.up);
}
public void SetName(string text) => playerName.text = text;
public void SetController(string text) => controller.text = text;
}