Hi
i have background music playing throughout the scenes,i cant figure it out how to stop bck music on game scene enter,this is my code. What is the best solution?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Music : MonoBehaviour
{
static Music instance = null;
void Awake()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
GameObject.DontDestroyOnLoad(gameObject);
}
}
public void ToggleSound()
{
if (PlayerPrefs.GetInt("Muted", 0) == 0)
{
PlayerPrefs.SetInt("Muted", 1);
}
else
{
PlayerPrefs.SetInt("Muted", 0);
}
}
}