I’m trying to play a sound when I press a button. It plays the first time, but when I go back to the same scene and press it again it doesn’t play. I think that I’ve found the problem, but I have no idea on how to solve it. Here is the script for the music:
using UnityEngine;
using System.Collections;
public class ButtonSound : MonoBehaviour {
public AudioClip buttonSound;
private static ButtonSound instance = null;
private AudioSource source;
public static ButtonSound Instance{
get { return instance; }
}
void Awake() {
source = GetComponent<AudioSource>();
if(instance != null && instance != this) {
Destroy(this.gameObject);
return;
}else{
instance = this;
}
DontDestroyOnLoad(this.gameObject);
}
public void Play(){
source.Play();
}
}
On the button (UI) I’m using pointer down to start the “Play” function.
From what I can find out the problem is that when I start the scene the script is there, but when I go back to the same scene it’s gone. (I’ve included pictures of the before and after):