I have couple of different scenes and I would like to play different tunes in specific scenes. I created a game object and attached an audio clip and a script. The script basically keeps Unity away from destroying. So it can play on different scenes.
using UnityEngine;
public class OSTPlayer : MonoBehaviour
{
private static OSTPlayer instance = null;
private static OSTPlayer Instance
{
get { return instance; }
}
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
}
else
{ instance = this; }
DontDestroyOnLoad(this.gameObject);
}
}
On a specific scene, I would like to change the audio clip, so I can play a different sound file. I wrote a code below (attached to a empty game object) and it looks it changes the audio clip. But there is no sound coming, like stop playing.
using UnityEngine;
using UnityEngine.SceneManagement;
public class StreetNavigate : MonoBehaviour
{
public AudioClip clip1;//I am dragging n dropping from the editor
private AudioSource BGMaudioSource;
private void Start()
{
BGMaudioSource = GameObject.FindGameObjectWithTag("OST1").GetComponent<AudioSource>();
BGMaudioSource.clip = clip1;
}
}
Am I doing mistakes or what is the problem?