TKK_E32231768/Assets/6Script/BackSound.cs

30 lines
741 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackSound : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
if (GameObject.Find("backsound on") == null)
{
DontDestroyOnLoad(gameObject);
GetComponent<AudioSource>().Play();
gameObject.name = "backsound on";
PlayerPrefs.SetFloat("volume", 05);
}
else
{
PlayerPrefs.SetFloat("volume", 0);
GetComponent<AudioSource>().Stop();
}
}
// Update is called once per frame
void Update()
{
GetComponent<AudioSource>().volume = PlayerPrefs.GetFloat("volume");
}
}