123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SoundMgr : MonoBehaviour
- {
- public AudioSource audiosource;
- public static SoundMgr _instance;
- void Awake()
- {
- audiosource = gameObject.AddComponent<AudioSource>();
- audiosource.playOnAwake = false;
- _instance = this;
- }
-
-
-
-
-
-
-
-
-
- public void PlayMusicByName(string name, bool loop)
- {
- AudioClip clip = Resources.Load<AudioClip>("Sounds/" + name);
- if (audiosource.isPlaying)
- {
- audiosource.Stop();
- }
- audiosource.clip = clip;
- audiosource.loop = loop;
- audiosource.Play();
- }
- }
|