-AUTEUR: minirop
-DESCRIPTION : Musique qui ne se coupe pas entre les scènes.
-UTILISATION : Créez un préfab qui ne contienne que ce script et un composant AudioSource avec votre musique. Ensuite, ajoutez ce préfab à toutes vos scènes et cochez "Keep Playing" sur celles qui doivent jouer la musique.
-SCRIPT :
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class NonStopPlay : MonoBehaviour {
public bool keepPlaying = false;
public static NonStopPlay NSPlay;
void Awake()
{
if(NSPlay == null)
{
NSPlay = this;
DontDestroyOnLoad(gameObject);
}
else
{
var audioSource = NSPlay.GetComponent<AudioSource>();
if(keepPlaying)
{
if(!audioSource.isPlaying)
{
audioSource.Play();
}
}
else
{
if(audioSource.isPlaying)
{
audioSource.Stop();
}
}
Destroy(gameObject);
}
}
}