И мой якорный скрипт:
Код: Выделить всё
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class ARObjectSpawner : MonoBehaviour
{
public GameObject prefab;
private ARRaycastManager raycastManager;
private ARAnchorManager anchorManager;
private List hits = new List();
void Start()
{
raycastManager = FindObjectOfType();
anchorManager = FindObjectOfType();
}
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
if (raycastManager.Raycast(touch.position, hits, TrackableType.PlaneWithinPolygon))
{
Pose hitPose = hits[0].pose;
GameObject spawnedObject = Instantiate(prefab, hitPose.position, hitPose.rotation);
ARAnchor anchor = anchorManager.AddAnchor(new Pose(hitPose.position, Quaternion.identity));
if (anchor != null)
{
spawnedObject.transform.SetParent(anchor.transform);
}
else
{
Debug.Log("Failed to create anchor.");
}
}
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -an-offset
Мобильная версия