Unity2D: Muting audio Clip problems

I’m trying to create a mute button (that goes both way, e.g mute and un-mute) using button onclick OnClick

So far I’m not having the greatest luck. I made this:

  mute = !mute;
	if (mute){
		gameObject.GetComponent<Gamestartsound>().volume = 0;
	}else
	{
		gameObject.GetComponent<Gamestartsound>().volume = 0;
	}

To achieve what I’m trying to do but getting errors:

error CS0118: UI_ManagerScripts.Gamestartsound' is a field’ but a `type’ was expected

and

error CS0118: UI_ManagerScripts.Gamestartsound' is a field’ but a `type’ was expected

anyway this is my full UIManager script, I did the audio like that because I was having some issues earlier but it’s better now so yeah:

public AudioClip Gamestartsound;
public GameObject Music;
public PlayerMovement playerMovementRef;
private bool mute;

public void DisableBoolAnimator(Animator anim)
{
	anim.SetBool ("IsDisplayed", false);
}

public void EnableBoolAnimator(Animator anim)
{
	anim.SetBool ("IsDisplayed", true);
}

public void NavigateTo(int scene)
{
	Application.LoadLevel ("Game Level");
	Movement.Restart ();
}
public void Mute ()
{
	mute = !mute;
	if (mute){
		gameObject.GetComponent<Gamestartsound>().volume = 0;
	}else
	{
		gameObject.GetComponent<Gamestartsound>().volume = 0;
	}
}

public void ExitGame()
{
	Application.Quit ();
}	
public void PauseGame()
{
	Time.timeScale = 0;
	playerMovementRef.enabled = false;
}

public void UnPauseGame()
{
	Time.timeScale = 1;
	playerMovementRef.enabled = true;
	AudioSource.PlayClipAtPoint (Gamestartsound, transform.position);
}

}

Try this approach

using UnityEngine;
using System;

public class UI_ManagerScripts : MonoBehaviour
{
    public AudioClip Gamestartsound;
    public GameObject Music;
    public PlayerMovement playerMovementRef;

    public bool playSoundOnAwake = false; // change this as necessary
    public bool loopSound = true;         // change this as necessary

    private AudioSource audioSource;

    void Start()
    {
        // get a reference to an AudioSource component
        // do this here once
        if (GetComponent<AudioSource>() == null)
        {
            audioSource = gameObject.AddComponent<AudioSource>();
        }
        else
        {
            audioSource = gameObject.GetComponent<AudioSource>();
        }
        audioSource.playOnAwake = playSoundOnAwake;
        audioSource.loop = loopSound;
        if (playSoundOnAwake)
        {
            PlayGamestartSound();
        }
    }

    public void DisableBoolAnimator(Animator anim)
    {
        anim.SetBool ("IsDisplayed", false);
    }

    public void EnableBoolAnimator(Animator anim)
    {
        anim.SetBool ("IsDisplayed", true);
    }

    public void NavigateTo(int scene)
    {
        Application.LoadLevel ("Game Level");
        Movement.Restart ();
    }
    public void Mute ()
    {
        audioSource.mute = !audioSource.mute;
    }

    public void ExitGame()
    {
        Application.Quit ();
    }    

    public void PauseGame()
    {
        Time.timeScale = 0;
        playerMovementRef.enabled = false;
    }

    public void UnPauseGame()
    {
        Time.timeScale = 1;
        playerMovementRef.enabled = true;
        PlayGamestartSound();
    }

    public void PlayGamestartSound()
    {
        audioSource.PlayClipAtPoint (Gamestartsound, transform.position);
        
        // consider using this instead 
        // audioSource.PlayOneShot(GamestartSound);
    }
}

Muting is done through the AudioSource. The code above adds one to the current GameObect in the Start() function if one does not already exist and gets a reference to it. It then uses it to mute and play the Gamestartsound AudioClip.

It is not apparent from your code if Gamestartsound is background music or not so two public variable were added to initialize the AudioSource properly

public bool playSoundOnAwake = false; // change this as necessary
public bool loopSound = true;         // change this as necessary - if not Background music set to false