37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class RayInfoUI : MonoBehaviour
|
|
{
|
|
private TextMeshProUGUI infoText;
|
|
private bool infoTextReady = false;
|
|
|
|
// Start is called before the first frame update
|
|
private void Start()
|
|
{
|
|
try
|
|
{
|
|
infoText = transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>();
|
|
infoTextReady = true;
|
|
}
|
|
catch (UnityException)
|
|
{
|
|
infoTextReady = false;
|
|
}
|
|
}
|
|
|
|
public void UpdateInfo(string info, Vector3 infoPosition, Color infoColor, Camera facetoCamera)
|
|
{
|
|
if (!infoTextReady)
|
|
{
|
|
infoText = transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>();
|
|
}
|
|
infoText.text = info;
|
|
infoText.color = infoColor;
|
|
transform.position = infoPosition;
|
|
Vector3 v = facetoCamera.transform.position - infoPosition;
|
|
v.x = v.z = 0.0f;
|
|
transform.LookAt(facetoCamera.transform.position - v);
|
|
transform.Rotate(0, 180, 0);
|
|
}
|
|
} |