using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Shoot : MonoBehaviour { public GameObject objMsg; Text txtMsg; // Use this for initialization void Start () { txtMsg = objMsg.gameObject.GetComponent(); } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { Debug.DrawLine(ray.origin, hit.point); Debug.Log(hit.transform.tag); txtMsg.text = hit.transform.tag; } } } }