-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrackingTarget.cs
More file actions
100 lines (85 loc) · 2.99 KB
/
TrackingTarget.cs
File metadata and controls
100 lines (85 loc) · 2.99 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.EventSystems;
using PupilLabs;
namespace ObjBehaviour
{
public class TrackingTarget : MonoBehaviour
{
public Color targetLockedColor = new Color(37, 214, 243);
public Color targetOnColor = Color.red;
public float targetOnTime = 0f;
public AudioClip colorChangeClip;
AudioSource cubeAudio;
MeshRenderer rend;
int cubeLayer;
Color originalColor;
// Start is called before the first frame update
void Awake()
{
rend = GetComponent<MeshRenderer>();
cubeAudio = GetComponent<AudioSource>();
originalColor = rend.material.color;
Char[] clone = { '(', 'C', 'l', 'o', 'n', 'e', ')' };
cubeLayer = LayerMask.NameToLayer(gameObject.name.TrimEnd(clone));
enabled = false;
}
// Update is called once per frame
void Update()
{
if (SpawnManager.redCubes == cubeLayer)
{
if (enabled) //check if the hitpoint is on the cube
{
targetOnTime += Time.deltaTime;
}
if (targetOnTime >= 3.0f) //check if the floating time of the hitpoint is greater than 3 seconds,
//if so, color -> ColorChange
//if not, the color should change back to its original color when the hitpoint leaves
{
ColorChange();
SoundEffectPlay();
}
}
}
private void OnEnable()
{
if (rend.material.color != targetOnColor) //make sure the color won't change back to blue if the cube is red
{
Material[] objMaterials = rend.materials;
foreach (Material material in objMaterials)
{
material.color = targetLockedColor;
}
}
}
private void OnDisable()
{
targetOnTime = 0f;
if (rend.material.color == targetLockedColor)
{
Material[] objMaterials = rend.materials;
foreach (Material material in objMaterials)
{
material.color = originalColor;
}
}
}
void ColorChange()
{
Material[] objMaterials = rend.materials;
foreach (Material material in objMaterials)
{
material.color = targetOnColor;
}
SpawnManager.redCubes += 1;
}
void SoundEffectPlay()
{
cubeAudio.clip = colorChangeClip;
cubeAudio.Play();
}
}
}