ClientServer/Client/Assets/Scripts/UI/NameUIFollow.cs
TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

36 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
public class NameUIFollow : MonoBehaviour
{
public Collider RootParentCollider;
public TextMeshProUGUI PlayersNameTag;
private void Update()
{
if (Player.Instance.GetPlayerFirstPersonCamera())
{
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Player.Instance.GetPlayerFirstPersonCamera());
bool isSeen = GeometryUtility.TestPlanesAABB(planes, RootParentCollider.bounds) &&
Vector3.Distance(RootParentCollider.gameObject.transform.position,
Player.Instance.GetPlayerFirstPersonCameraPosition()) < 10.0f;
PlayersNameTag.enabled = isSeen;
}
else
{
Debug.Log("Local Player First person camera is null. This should not happen.");
}
}
private void LateUpdate()
{
if (Player.Instance != null)
transform.rotation = Quaternion.LookRotation(transform.position - Player.Instance.GetPlayerFirstPersonCameraPosition());
}
}