Skip to content

Instantly share code, notes, and snippets.

@yuseinishiyama
Created January 17, 2014 02:34
Show Gist options
  • Save yuseinishiyama/8467497 to your computer and use it in GitHub Desktop.
Save yuseinishiyama/8467497 to your computer and use it in GitHub Desktop.
For syncing events with audio. (For Unity3d)
using UnityEngine;
using System.Collections;
[AddComponentMenu("Scripts/BGM/Seeker")]
public class Seeker : MonoBehaviour
{
public float seekTime {
get {
return isSeeking ? (float)AudioSettings.dspTime - startTimeByDspTime : 0;
}
}
float startTimeByDspTime;
bool isSeeking = false;
public void StartSeeking ()
{
isSeeking = true;
startTimeByDspTime = (float)AudioSettings.dspTime;
}
public void StopSeeking ()
{
startTimeByDspTime = 0;
isSeeking = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment