MIF_E31230979/Assets/Scripts/HomePage/AudioManager.cs

30 lines
627 B
C#

using UnityEngine;
public class AudioManager : MonoBehaviour
{
public static AudioManager instance;
private AudioSource source;
void Awake()
{
// Logika biar AudioManager ini abadi dan cuma ada satu
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
source = GetComponent<AudioSource>();
}
else
{
Destroy(gameObject);
}
}
public void PlayClick(AudioClip clip)
{
if (source != null && clip != null)
{
source.PlayOneShot(clip);
}
}
}