27 lines
780 B
C#
27 lines
780 B
C#
// Assets/_Project/Scripts/Audio/MusicPlayer.cs
|
|
using UnityEngine;
|
|
|
|
namespace TD.Audio
|
|
{
|
|
/// <summary>
|
|
/// Plays a single looping music track for the scene it lives in.
|
|
/// Add to a GameObject in the scene, assign a clip, and it starts on load.
|
|
/// </summary>
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class MusicPlayer : MonoBehaviour
|
|
{
|
|
[SerializeField] private AudioClip clip;
|
|
[Range(0f, 1f)]
|
|
[SerializeField] private float volume = 1f;
|
|
|
|
private void Start()
|
|
{
|
|
var src = GetComponent<AudioSource>();
|
|
src.clip = clip;
|
|
src.volume = volume;
|
|
src.loop = true;
|
|
src.playOnAwake = false;
|
|
src.Play();
|
|
}
|
|
}
|
|
}
|