SWS-Smarta / project /Assets /Scripts /Game /DinoAmbientLoop.cs
alfapro's picture
Clean deploy: Code only for SWS
defab59
Raw History Blame Contribute Delete
693 Bytes
using UnityEngine;
public class DinoAmbientLoop : MonoBehaviour
{
public AudioSource ambientSource;
public AudioClip ambientClip;
public float volume = 0.35f;
void Awake()
{
if (ambientSource == null)
{
ambientSource = gameObject.AddComponent<AudioSource>();
ambientSource.loop = true;
ambientSource.playOnAwake = false;
ambientSource.spatialBlend = 0f;
}
}
void Start()
{
if (ambientClip == null || ambientSource == null)
return;
ambientSource.clip = ambientClip;
ambientSource.volume = Mathf.Clamp01(volume);
ambientSource.Play();
}
}