Mute Button doesn't work?!

Hi!

I wanted to make a Mutebutton with this script =

Name on Script: Mute

function OnMouseDown(){
  if(audio.isPlaying){
    audio.Stop();
  } else {
    audio.Play();
  }    
}

And then i tryed to make this one ->

Name: MuteSound

AudioSource.mute
var mute : bool

// Mutes-Unmutes the sound of this transfor each time the user presses space. 

function Update() {
if(Input.GetKeyDown(KeyCode.Space)) {
if(audio.mute)
audio.mute = false;
else
audio.mute = true;
} 
}

But both of them failed with there name, Error = Script file name does not match the name of the class defined in script...

So why does it not work? And what shall they be named as? :)

Thanks.

(Sorry my bad English)

I've only ever seen that error for mono (c#) .cs files. Are you using the right language?

Something like this will accomplish what your above code should and does not generate any errors:

Mute.js

function OnMouseDown() {
    if(audio.isPlaying) audio.Stop();
    else audio.Play();
}

MuteSound.js

function Update() {
    if(Input.GetKeyDown(KeyCode.Space)) audio.mute = !audio.mute;
}

Mute.cs

using UnityEngine;

public class Mute : MonoBehaviour {
    public void OnMouseDown() {
        if(audio.isPlaying) audio.Stop();
        else audio.Play();
    }
}

or

MuteSound.cs

using UnityEngine;

public class MuteSound : MonoBehaviour {
    public void Update() {
        if(Input.GetKeyDown(KeyCode.Space)) audio.mute = !audio.mute;
    }
}