ARPlaceOnPlane.cs
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
public class ARPlaceOnPlane : MonoBehaviour
{
public ARRaycastManager arRaycaster;
public GameObject[] placeObject;
GameObject spawnObject;
public static bool isSetted = false;
void Update()
{
}
private void FixedUpdate()
{//UpdateCenterObject();
if (!isSetted)
{
PlaceObjectByTouch();
}
}
private void PlaceObjectByTouch() {
if (Input.touchCount > 0) {
Touch touch = Input.GetTouch(0); //터치값 얻어오기
List<ARRaycastHit> hits = new List<ARRaycastHit>();
if (arRaycaster.Raycast(touch.position, hits, TrackableType.Planes)) {
Pose hitPose = hits[0].pose;
if (!spawnObject) // 아직 오브젝트 미생성됐으면
{
int ran = Random.Range(0, 3);
spawnObject = Instantiate(placeObject[ran], hitPose.position, hitPose.rotation); // 생성하고
isSetted = true; // update문에서 바닥탐지/생성함수를 정지함
}
else {
spawnObject.transform.position = hitPose.position;
spawnObject.transform.rotation = hitPose.rotation;
}
}
}
}
}