46 lines
1.0 KiB
C#
46 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace TON
|
|
{
|
|
public class SoundManager : MonoBehaviour
|
|
{
|
|
public AudioSource bgSound;
|
|
|
|
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);
|
|
}
|
|
|
|
public void BgSoundPlay(AudioClip clip)
|
|
{
|
|
bgSound.clip = clip;
|
|
bgSound.loop = true;
|
|
bgSound.volume = 1f;
|
|
bgSound.Play();
|
|
}
|
|
}
|
|
}
|