forked from Gkxd/Rhythmify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicWrapper.cs
More file actions
35 lines (31 loc) · 1.07 KB
/
Copy pathMusicWrapper.cs
File metadata and controls
35 lines (31 loc) · 1.07 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
/* @Author: Gkxd
*
* A wrapper for attaching information to Audio Sources and controlling music loops
*
* */
using UnityEngine;
using System.Collections;
namespace Rhythmify {
public class MusicWrapper : MonoBehaviour {
public int BPM;
public float loopLength;
public float loopThreshold;
private AudioSource audioSource;
private AudioClip audioClip;
public void Start() {
if (gameObject.tag != "Rhythmify_Music") {
Debug.LogError("GameObjects with a MusicWrapper component must be tagged \"Rhythmify_Music\".");
Debug.Break();
}
audioSource = gameObject.GetComponent<AudioSource>();
audioClip = audioSource.clip;
}
public void Update() {
if (loopLength > 0 && loopThreshold > 0) {
if (audioSource.timeSamples > loopThreshold * audioClip.frequency) {
audioSource.timeSamples -= Mathf.RoundToInt(loopLength * audioClip.frequency);
}
}
}
}
}