- Home /
Question by
BrettHarte · Aug 09, 2018 at 04:24 PM ·
raycastcanvasraycasting
Using Raycasting in AR to display UI
Hello,
I've been working on a AR app. When you touch an object, using raycasting, I need a canvas to appear with addition text/information.
I've tested the raycasting with the touch screen and it works fine, I just can't seem to get the canvas to appear for some reason.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class TouchTest : MonoBehaviour {
public Canvas myCanvas;
Ray ray;
RaycastHit hit;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
Debug.DrawRay(ray.origin, ray.direction * 20, Color.red);
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
myCanvas.enabled = true;
}
}
}
}
I was wondering if anyone had any experience with AR and raycasting, or with the product EasyAR? Any ideas or tips would be greatly appreciated.
Thanks -Brett
Comment