44 lines
911 B
C#
44 lines
911 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class AudioSync : MonoBehaviour
|
|
{
|
|
//set these in the inspector!
|
|
public AudioSource master;
|
|
public AudioSource slave;
|
|
public float curSample;
|
|
|
|
public bool smooth;
|
|
public float smoothInterval = 0.5f;
|
|
public float replayOffset;
|
|
float t;
|
|
private void Awake()
|
|
{
|
|
t = smoothInterval;
|
|
}
|
|
void FixedUpdate()
|
|
{
|
|
if (smooth)
|
|
{
|
|
if(t < smoothInterval)
|
|
{
|
|
t += Time.deltaTime;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
t = 0;
|
|
slave.time = Time.time - replayOffset;
|
|
master.time = Time.time-replayOffset;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
slave.time = Time.time;
|
|
master.time = Time.time;
|
|
}
|
|
|
|
}
|
|
}
|