一、Raycasting简介
Raycasting:直译为射线投射,从指定的位置,往一个方向发射一条无限长的射线,当碰撞到平面和点云后,返回被碰撞的平面和点云集合。
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
/// <summary>射线投射测试</summary>
[RequireComponent(typeof(ARRaycastManager))]
public class ARRaycastTest : MonoBehaviour
{
private static List<ARRaycastHit> Hits;
private ARRaycastManager mRaycastManager;
private void Start()
{
Hits = new List<ARRaycastHit>();
mRaycastManager = GetComponent<ARRaycastManager>();
}
//从屏幕坐标中发射一条射线,检测是否碰撞到物体,返回碰撞到物体的位置信息