(サンプルコード)
using UnityEngine;
using TMPro;
public class AimController : MonoBehaviour
{
public TextMeshProUGUI nameLabel;
void Update()
{
transform.position = Input.mousePosition;
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,out hit))
{
GameObject target = hit.collider.gameObject;
nameLabel.text = "" + target.name;
}
else
{
nameLabel.text = "";
}
}
}