How to play audio in child classes

I am writing a script that allows the user to bind a sound to a key. I have writen a main class that loads audio with WWW and then plays it with this code:

public function playaudio(key : String)
	{
		if(Input.GetKeyDown(key))
		{
			Debug.Log("key pressed");
			if(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
			{
			audio.loop = true;
			audio.Play(sound);
			}else{
			audio.Play(sound);
			audio.loop = false;
			}
		}
	}

the compiler has no errors but when I try to use more than one child class it will only play the audio from the first child class

I’m not sure if this would work, but it’s worth a try. You could try creating a public reference for the script on the parent object and reference each child through the editor. Then call the component for the audio of each child.

Just a thought, I’m not sure if this would work.