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