HeavenStudioPlus/Assets/Scripts/Util/Sound.cs

55 lines
1.4 KiB
C#
Raw Normal View History

2021-12-21 01:10:49 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Util
{
public class Sound : MonoBehaviour
{
public AudioClip clip;
2022-01-15 07:08:23 +00:00
public float pitch = 1;
2021-12-21 01:10:49 +00:00
private AudioSource audioSource;
2022-01-15 07:08:23 +00:00
private int pauseTimes = 0;
private float startTime;
2021-12-21 01:10:49 +00:00
private void Start()
{
audioSource = GetComponent<AudioSource>();
2022-01-15 07:08:23 +00:00
audioSource.clip = clip;
audioSource.pitch = pitch;
audioSource.PlayScheduled(Time.time);
startTime = Conductor.instance.songPosition;
2021-12-21 01:10:49 +00:00
}
2022-01-15 07:08:23 +00:00
private void Update()
2021-12-21 01:10:49 +00:00
{
2022-01-15 07:08:23 +00:00
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);
}
2021-12-21 01:10:49 +00:00
}
}
}