HeavenStudioPlus/Assets/Scripts/Util/Sound.cs
2022-01-15 02:08:23 -05:00

54 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Util
{
public class Sound : MonoBehaviour
{
public AudioClip clip;
public float pitch = 1;
private AudioSource audioSource;
private int pauseTimes = 0;
private float startTime;
private void Start()
{
audioSource = GetComponent<AudioSource>();
audioSource.clip = clip;
audioSource.pitch = pitch;
audioSource.PlayScheduled(Time.time);
startTime = Conductor.instance.songPosition;
}
private void Update()
{
if (Conductor.instance.isPaused && !Conductor.instance.isPlaying && pauseTimes == 0)
{
audioSource.Pause();
pauseTimes = 1;
print("paused");
}
else if (Conductor.instance.isPlaying && !Conductor.instance.isPaused && pauseTimes == 1)
{
audioSource.Play();
print("played");
pauseTimes = 0;
}
else if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused)
{
Destroy(this.gameObject);
}
if (Conductor.instance.songPosition > startTime + clip.length)
{
Destroy(this.gameObject);
}
}
}
}