25 lines
509 B
C#
25 lines
509 B
C#
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class MusicScript : MonoBehaviour
|
||
|
|
{
|
||
|
|
private AudioSource audioSource;
|
||
|
|
private void Awake()
|
||
|
|
{
|
||
|
|
DontDestroyOnLoad(transform.gameObject);
|
||
|
|
audioSource = GetComponent<AudioSource>();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void PlayMusic()
|
||
|
|
{
|
||
|
|
if (audioSource.isPlaying) return;
|
||
|
|
audioSource.Play();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void StopMusic()
|
||
|
|
{
|
||
|
|
audioSource.Stop();
|
||
|
|
}
|
||
|
|
}
|