forked from Zoytx/PhysicsAR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3rdLaw.cs
79 lines (52 loc) · 1.44 KB
/
3rdLaw.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.UI;
[RequireComponent(typeof(ARRaycastManager))]
public class thirdlaw : MonoBehaviour
{
public GameObject obj;
private GameObject spwn;
private ARRaycastManager arcman;
private Vector2 pos;
static List<ARRaycastHit> hits = new List<ARRaycastHit>();
//Getting the AR component from plugins
private void Awake()
{
arcman = GetComponent<ARRaycastManager>();
}
bool getpos(out Vector2 pos)
{
if (Input.touchCount > 0)
{
pos = Input.GetTouch(0).position;
return true;
}
pos = default;
return false;
}
//Placing the object and moving it around
void Update()
{
if(!getpos(out Vector2 pos))
return;
if (arcman.Raycast(pos, hits, TrackableType.PlaneWithinPolygon))
{
{
var hitPose = hits[0].pose;
hitPose.position.y = hitPose.position.y + 2;
if (spwn == null)
{
spwn = Instantiate(obj, hitPose.position, hitPose.rotation);
}
else
{
spwn.transform.position = hitPose.position;
}
}
}
}
//GameObject.find(obj).transform.position;
}