2075 / Unity / 2D / Звук
public AudioSource music;
void OnTriggerEnter2D(Collider2D other)
{
music.Play();
}
Якщо зробити видимим об'єкт зі звуком - він буде програвати звук
Звук переходить в наступну сцену
private void Awake()
{
GameObject[] musicObj = GameObject.FindGameObjectsWithTag("MusicFon");
if(musicObj.Length > 1)
{
Destroy(gameObject);
}
DontDestroyOnLoad(gameObject);
}
Зупинити всі звуки
AudioSource[] allAudioSources = FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
foreach (AudioSource audio in allAudioSources) {
audio.Stop();
}
Більше про звуки