Home »
»
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class ARHologramPlacement : MonoBehaviour
{
public GameObject hologramPrefab;
private ARRaycastManager raycastManager;
private GameObject spawnedObject;
static List hits = new List();
void Start()
{
raycastManager = GetComponent();
}
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 pose = hits[0].pose;
if (spawnedObject == null)
{
spawnedObject = Instantiate(hologramPrefab, pose.position, pose.rotation);
}
else
{
spawnedObject.transform.position = pose.position;
}
}
}
}
}
}

0 comments:
Post a Comment