Im create TextMeshPro from "Create -> 3D Object ->Text - TextMeshPro" How to receive mouse button click event for TextMeshPro? I tried via Physics.Raycast/Collider but it doesn't work. It's not "Create -> UI ->Text - TextMeshPro" though. I also tried to add GraphicRaycaster component to TextMeshPro as for UI element, but it doesn't work.I did not understand where to create EventSystem. I just added it as a component to TextMeshPro. Also tried to add Button Component to TextMeshPro.
public class Math : MonoBehaviour
{
// Start is called before the first frame update
GraphicRaycaster m_Raycaster;
PointerEventData m_PointerEventData;
void Start()
{
m_Raycaster = GameObject.Find("Solution").GetComponent<TextMeshPro>().GetComponent<GraphicRaycaster>();
m_EventSystem = GameObject.Find("Solution").GetComponent<TextMeshPro>().GetComponent<EventSystem>();
Solution = GameObject.Find("Solution").GetComponent<TextMeshPro>();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
m_PointerEventData = new PointerEventData(null);
m_PointerEventData.position = Input.mousePosition;
List<RaycastResult> results = new List<RaycastResult>();
m_Raycaster.Raycast(m_PointerEventData, results);
foreach (RaycastResult result in results) //Results - null
{
Debug.Log("Hit " + result.gameObject.name); //not enter
}
Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject.name == "Solution")
{
Debug.Log("Hit " + hit.collider.gameObject.name); //not enter
}
}
}
}
}