public void Play(string name) { soundScript s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.Log("lol f**k you we found no sound"); return; } s.source.Play(); }
//to call this function: sound.me.play(); public void Awake() { if (me != null) { Destroy(this); } me = this; sources = new AudioSource[sourceNum]; for (int i = 0; i < sourceNum; i++) { sources[i] = ((GameObject)Instantiate(sourcePrefab, Vector3.zero, Quaternion.identity, transform)).GetComponent <AudioSource>(); } }