I’m following the 2d Roguelike tutorial. In step 13 adding the sounds, I created a sound manager script in the scene. I then made it a prefab with the script and the 2 audio sources in the as a game component. I then added the SoundManager to my loader script, but I cannot drop in the prefab sound manager game component into the loader. The weird part is when I drag the prefab onto the public script variable in Loader in the Unity UI it highlights as a good link but doesn’t update when the mouse is released.
My scripts are the following.
public class Loader : MonoBehaviour
{
public GameManager GameManager;
public SoundManager SoundManager;
static Loader()
{
log4net.Config.BasicConfigurator.Configure(new ConsoleAppender(new SimpleLayout()));
}
private void Awake()
{
if (GameManager.Instance == null && this.GameManager != null)
{
Instantiate(this.GameManager);
}
if (SoundManager.Instance == null && this.SoundManager != null)
{
Instantiate(this.SoundManager);
}
}
public class SoundManager : MonoBehaviour
{
public static SoundManager Instance;
public AudioSource EfxSource;
public AudioSource MusicSource;
public float LowPitchRange = .95f;
public float HighPitchRange = 1.05f;
public void PlaySingle(AudioClip clip)
{
this.EfxSource.clip = clip;
this.EfxSource.Play();
}
public void RandomizeSfc(params AudioClip[] clips)
{
var randomIndex = Random.Range(0, clips.Length);
var randomPitch = Random.Range(this.LowPitchRange, this.HighPitchRange);
this.EfxSource.pitch = randomPitch;
this.EfxSource.clip = clips[randomIndex];
this.EfxSource.Pause();
}
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
else if (Instance != this)
{
Destroy(this.gameObject);
}
DontDestroyOnLoad(this.gameObject);
}
}