-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCopSpeechBehaviour.cs
105 lines (91 loc) · 2.01 KB
/
CopSpeechBehaviour.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using UnityEngine;
namespace Policeman
{
public class CopSpeechBehaviour : MonoBehaviour
{
public CopSpeechBehaviour(System.IntPtr ptr) : base(ptr) { }
public AudioSource speechSource;
public AudioClip[] speechClips;
public int maxQueueCount = 5;
private bool canSpeak;
private float delayTime = 0f;
private void Start()
{
speechSource.dopplerLevel = 0.5f;
}
private void Update()
{
if (!speechSource.isPlaying)
{
delayTime += Time.deltaTime;
if (delayTime > 2.5f)
{
delayTime = 0f;
float randomVal = Random.Range(0, 65535);
if (randomVal % 2f == 0f)
{
speechSource.clip = speechClips[Random.Range(0, speechClips.Length)];
speechSource.Play();
}
}
}
}
/*private void QueueClip(AudioClip[] array, AudioClip clip)
{
for (int i = 0; i < array.Length; i++)
{
if (array[i] == null)
{
array[i] = clip;
break;
}
// If we queue a clip, and it reaches outside the bounds of the array
// Simply replace the last element in the array with the clip we want
if (i > array.Length)
{
array[array.Length] = clip;
}
else if (i < 0)
{
if (array[i] == null)
array[i] = clip;
}
}
}
private void QueueClip(int index, AudioClip[] array, AudioClip clip)
{
if (array[index] == null)
{
array[index] = clip;
}
// If we queue a clip, and it reaches outside the bounds of the array
// Simply replace the last element in the array with the clip we want
if (index > array.Length)
{
array[array.Length] = clip;
}
else if (index < 0)
{
if (array[index] == null)
array[index] = clip;
}
else return;
}
private void RemoveClip(int index, AudioClip[] array)
{
if (array[index] != null)
array[index] = null;
}
private void RemoveClip(AudioClip clip, AudioClip[] array)
{
for(int i = 0; i < array.Length; i++)
{
if(array[i] == clip && array[i] != null)
{
array[i] = null;
break;
}
}
}*/
}
}