This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathDistanceManager.cs
76 lines (65 loc) · 2.16 KB
/
DistanceManager.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
using UnityEngine;
public class DistanceManager : MonoBehaviour
{
[SerializeField]
[Tooltip("Image Tracking manager that detects tracked images")]
ImageTrackingObjectManager m_ImageTrackingObjectManager;
/// <summary>
/// Get the <c>ImageTrackingObjectManger</c>
/// </summary>
public ImageTrackingObjectManager imageTrackingObjectManager
{
get => m_ImageTrackingObjectManager;
set => m_ImageTrackingObjectManager = value;
}
[SerializeField]
[Tooltip("Prefab to be spawned and showed between numbers based on distance")]
GameObject m_SumPrefab;
/// <summary>
/// Get the sum prefab
/// </summary>
public GameObject sumPrefab
{
get => m_SumPrefab;
set => m_SumPrefab = value;
}
GameObject m_SpawnedSumPrefab;
GameObject m_OneObject;
GameObject m_TwoObject;
float m_Distance;
bool m_SumActive;
const float k_SumDistance = 0.3f;
void Start()
{
m_SpawnedSumPrefab = Instantiate(m_SumPrefab, Vector3.zero, Quaternion.identity);
m_SpawnedSumPrefab.SetActive(false);
}
void Update()
{
m_OneObject = m_ImageTrackingObjectManager.spawnedOnePrefab;
m_TwoObject = m_ImageTrackingObjectManager.spawnedTwoPrefab;
if (m_ImageTrackingObjectManager.NumberOfTrackedImages() > 1)
{
m_Distance = Vector3.Distance(m_OneObject.transform.position, m_TwoObject.transform.position);
if (m_Distance <= k_SumDistance)
{
if (!m_SumActive)
{
m_SpawnedSumPrefab.SetActive(true);
m_SumActive = true;
}
m_SpawnedSumPrefab.transform.position = (m_OneObject.transform.position + m_TwoObject.transform.position) / 2;
}
else
{
m_SpawnedSumPrefab.SetActive(false);
m_SumActive = false;
}
}
else
{
m_SpawnedSumPrefab.SetActive(false);
m_SumActive = false;
}
}
}