67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ThunderEffects : MonoBehaviour
|
|
{
|
|
[SerializeField] private Animator[] thunderAnimator;
|
|
private AudioSource _audioSource;
|
|
public AudioClip audioClip;
|
|
public float thunderSoundMinWaitTime = 30f;
|
|
public float thunderSoundMaxWaitTime = 120f;
|
|
public bool ShouldPlayThunder = true;
|
|
private bool _hasPlayed;
|
|
private bool _ThunderLightingHasPlayed;
|
|
|
|
private void Start()
|
|
{
|
|
_audioSource = GetComponent<AudioSource>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!_hasPlayed && ShouldPlayThunder)
|
|
{
|
|
StartCoroutine(Thunder());
|
|
_hasPlayed = true;
|
|
_ThunderLightingHasPlayed = false;
|
|
}
|
|
}
|
|
|
|
public void StopThunderEffects()
|
|
{
|
|
ShouldPlayThunder = false;
|
|
}
|
|
|
|
public void ContinueThunderEffects()
|
|
{
|
|
ShouldPlayThunder = true;
|
|
}
|
|
|
|
public void PlayThunder()
|
|
{
|
|
_ThunderLightingHasPlayed = false;
|
|
StartCoroutine(Thunder());
|
|
}
|
|
|
|
IEnumerator Thunder()
|
|
{
|
|
yield return new WaitForSeconds(Random.Range(thunderSoundMinWaitTime,thunderSoundMaxWaitTime));
|
|
if (!_ThunderLightingHasPlayed)
|
|
{
|
|
foreach (Animator thunderAnim in thunderAnimator)
|
|
{
|
|
thunderAnim.SetBool("IsThundering", true);
|
|
_ThunderLightingHasPlayed = true;
|
|
}
|
|
}
|
|
yield return new WaitForSeconds(1.25f);
|
|
foreach (Animator thunderAnim in thunderAnimator)
|
|
{
|
|
thunderAnim.SetBool("IsThundering", false);
|
|
}
|
|
_audioSource.PlayOneShot(audioClip);
|
|
_hasPlayed = false;
|
|
}
|
|
}
|