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