music
This commit is contained in:
parent
2286de6fbc
commit
d14305d804
10 changed files with 218 additions and 27 deletions
27
Assets/_Project/Scripts/Audio/MusicPlayer.cs
Normal file
27
Assets/_Project/Scripts/Audio/MusicPlayer.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue