mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-30 21:43:09 +00:00
54 lines
1.4 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|