61 lines
1.2 KiB
C#
61 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class KumpulanSuara : MonoBehaviour
|
|
{
|
|
|
|
public static KumpulanSuara instance;
|
|
|
|
public AudioClip[] Clip;
|
|
public AudioClip[] ClipMateri;
|
|
|
|
public AudioSource source_sfx; //sound effect
|
|
|
|
public AudioSource source_bgm; //background musik
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = this;
|
|
DontDestroyOnLoad(this.gameObject);
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
public void Panggil_Sfx(int id)
|
|
{
|
|
source_sfx.PlayOneShot(Clip[id]);
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Mainkan suara materi berdasarkan ID
|
|
/// </summary>
|
|
public void Panggil_SuaraMateri(int id)
|
|
{
|
|
if (id >= 0 && id < ClipMateri.Length)
|
|
{
|
|
source_sfx.PlayOneShot(ClipMateri[id]);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("ID Suara Materi tidak ditemukan: " + id);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fungsi ini bisa dipanggil langsung dari tombol dengan parameter ID
|
|
/// </summary>
|
|
public void DengarkanMateriDariButton(int idSuaraMateri)
|
|
{
|
|
Panggil_SuaraMateri(idSuaraMateri);
|
|
}
|
|
}
|
|
|
|
|