namespace UnityEngine.AzureSky { public sealed class AzureThunderPrefab : MonoBehaviour { /// The lightning frequency that affect the clouds and scene while this thunder prefab is playing. public AnimationCurve lightFrequency { get => m_lightFrequency; set => m_lightFrequency = value; } [SerializeField] private AnimationCurve m_lightFrequency = null; /// The delay to play the thunder audio clip after this prefab instantiation. public float audioDelay { get => m_audioDelay; set => m_audioDelay = value; } [SerializeField] private float m_audioDelay = 0.0f; /// The reference to the AudioSource component attached to this prefab. private AudioSource m_audioSource = null; /// The reference to the directional light used to lighting the scene while this thunder is playing. private Light m_light = null; // Internal use private float m_time = 0.0f; private bool m_canPlayAudioClip = true; private void Start() { m_audioSource = GetComponent(); m_light = GetComponent(); } private void Update() { m_time += Time.deltaTime; m_light.intensity = m_lightFrequency.Evaluate(m_time / m_audioSource.clip.length); Shader.SetGlobalFloat (AzureShaderUniforms.ThunderLightningEffect, m_light.intensity); if (m_time >= m_audioDelay && m_canPlayAudioClip) { m_audioSource.Play(); m_canPlayAudioClip = false; } if(m_time >= m_audioDelay + m_audioSource.clip.length) Destroy(gameObject); } } }