Created
April 4, 2022 00:35
-
-
Save 314pies/5ad0693043747ed5a1afd990bc8fd373 to your computer and use it in GitHub Desktop.
ARRaycasting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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