Files
M-Gameton-06/Gameton-06/Assets/Gameton/Scripts/Sound/SoundManager.cs
2025-03-01 18:57:49 +09:00

36 lines
808 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace TON
{
public class SoundManager : MonoBehaviour
{
public static SoundManager instance;
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(instance);
}
else
{
Destroy(gameObject);
}
}
public void SFXPlay(string sfxName, AudioClip clip)
{
GameObject go = new GameObject(sfxName + "Sound");
AudioSource audiosource = go.AddComponent<AudioSource>();
audiosource.clip = clip;
audiosource.Play();
Destroy(go, clip.length);
}
}
}