I was following a tutorial on making an AudioManager and my code won't work. Can anyone find the problem, please?
using UnityEngine.Audio;
using UnityEngine;
using System;
public class AudioManager : MonoBehaviour
{
public Sound[] sounds;
//is called for before everything starts
void Awake()
{
foreach (Sound s in sounds)
{
s.source = gameObject.AddComponent();
s.source.clip = s.clip;
s.source.volume = s.volume;
s.source.pitch = s.pitch;
}
}
public void play(string name)
{
Sound s = Array.Find(sounds, sound => sound.name ==name);
s.source.Play();
}
}
↧