Hi,
I did the AR Foundation tutorial
Instead of the plane I have a small village and now I would like to click on the individual houses with a Raycast to get the names of it.
Unfortunately this does not work for me. I have BoxCollider around my houses and Unity also has no error message.
I also found this video
and rebuilt it with Vuforia and it works here. Does this not work here with ARFoundation?
This is the code:
private Text label;
private GameObject bg_label;
// Use this for initialization
void Start()
{
label = GameObject.Find("LabelName").GetComponent<Text>();
label.text = "";
bg_label = GameObject.Find("BgLabel");
bg_label.SetActive(false);
}
// Update is called once per frame
void Update()
{
if ((Input.GetTouch(0).phase == TouchPhase.Stationary) || (Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(0).deltaPosition.magnitude < 1.2f))
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
bg_label.SetActive(true);
label.text = hit.transform.name.ToString();
}
else
{
bg_label.SetActive(false);
label.text = "";
}
}
}
Thank you
Lukas