Answers for "how to make the music last forver unity"

C#
0

music that stays when you change scene unity

using UnityEngine;
public class MusicClass : MonoBehaviour {
  private AudioSource _audioSource;
  private void Awake()
  {
    DontDestroyOnLoad(transform.gameObject);
    _audioSource = GetComponent<AudioSource>();
  }
  public void PlayMusic()
  {
    if (_audioSource.isPlaying) return;
    _audioSource.Play();
  }
  public void StopMusic()
  {
    _audioSource.Stop();
  }
}
Posted by: Guest on July-25-2020
0

how to make the music last forver unity

GameObject.FindGameObjectWithTag("Music").GetComponent<MusicClass>().PlayMusic();
Posted by: Guest on December-20-2020

Code answers related to "how to make the music last forver unity"

C# Answers by Framework

Browse Popular Code Answers by Language