Music On/Off Switch

I’m attempting to add a control so users can turn the music off or on. After researching this code seems to be like other answers here, but it gives an error message.

var musicname	: AudioClip;

function OnGUI()
{
  if (GUI.Button(Rect(Screen.width-50,5,45,20),"Music"))
  	{
  	  if (musicname.isPlaying)
  	  	{
  	  	musicname.Pause (musicname);
  	  	}
  	  	else
  	  	{
  	  	musicname.Play (musicname);  	  	
  	  	}
  	}
}

The error message it gives when clicked is:

MissingMethodException: Method not found: 'UnityEngine.AudioClip.Play'.
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey12.<>m__6 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)

I have dragged the name of the audio clip into the inspector slot for it. Any help appreciated - as we all know, it’s nice to be able to control the music in a game and I’d like to give that option :slight_smile:

AudioClip does not play audio, an AudioSource does.

Oookay, after further reasearch I don’t quite understand how I fixed it, but I got another script example that did something kinda the same and worked across. I could have sworn I had the code set up like this to begin with! Putting this here for anyone else looking for an answer instead of a link. Make sure an audio source is attached to whatever the script is attached to and set to play on awake and is on a loop.

@script RequireComponent(AudioSource)

function OnGUI()
{
if (GUI.Button(Rect(Screen.width-55,5,45,20),"Music"))
  {
    if (audio.isPlaying)
      {
      audio.Pause ();
      }
      else
      {
      audio.Play ();          
      }
   }
}