forked from mdotstrange/CustomBehaviorDesignerTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayRandomSingleAudio.cs
44 lines (38 loc) · 1.35 KB
/
PlayRandomSingleAudio.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
using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityAudioSource
{
[TaskCategory("Basic/AudioSource")]
[TaskDescription("Randomizes the pitch of a an audioclip before playing. Make min,max = 1 for no random pitch.")]
public class PlayRandomSingleAudio : Action
{
public SharedGameObject AudioSourceGO;
public SharedAudioClip audioClip;
public SharedFloat volume = 1f;
public SharedFloat randomPitchMin;
public SharedFloat randomPitchMax;
public override TaskStatus OnUpdate()
{
if (AudioSourceGO.Value != null)
{
GameObject go = AudioSourceGO.Value.gameObject;
AudioSource audio = go.GetComponent<AudioSource>();
AudioClip daClip = audioClip.Value;
audio.clip = daClip;
audio.pitch = Random.Range(randomPitchMin.Value, randomPitchMax.Value);
audio.Play();
return TaskStatus.Success;
}
else
{
return TaskStatus.Failure;
}
}
public override void OnReset()
{
gameObject = null;
randomPitchMin = 0.80f;
randomPitchMax = 1.20f;
volume = 1;
}
}
}