using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class rayInfoUI : MonoBehaviour
{
    TextMeshProUGUI infoText;
    bool infoTextReady = false;
    // Start is called before the first frame update
    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);
    }
}
