Skip to content

Instantly share code, notes, and snippets.

@314pies
Created April 4, 2022 00:35
Show Gist options
  • Save 314pies/5ad0693043747ed5a1afd990bc8fd373 to your computer and use it in GitHub Desktop.
Save 314pies/5ad0693043747ed5a1afd990bc8fd373 to your computer and use it in GitHub Desktop.
ARRaycasting.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class ARRaycasting : MonoBehaviour
{
public GameObject cube;
[SerializeField]
ARRaycastManager m_RaycastManager;
List<ARRaycastHit> hits = new List<ARRaycastHit>();
void Update()
{
var rayCastPoint = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f));
if (m_RaycastManager.Raycast(rayCastPoint, hits, TrackableType.PlaneWithinPolygon)) {
var hitPose = hits[0].pose;
cube.transform.position = hitPose.position;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment