I am trying to follow a course to learn Unity, and I do exactly what appears in the video:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThunderClap : MonoBehaviour
{
bool canFlicker = true;
private Light light;
public AudioClip clip;
void Awake()
{
light = GetComponent<Light>();
}
private void Update()
{
StartCoroutine(Flicker());
}
IEnumerator Flicker()
{
if (canFlicker)
{
canFlicker = false;
audio.PlayOneShot(clip);
light.enabled = true;
yield return new WaitForSeconds(Random.Range(0.1f,0.4f));
light.enabled = false;
yield return new WaitForSeconds(Random.Range(0.1f,5f));
canFlicker = true;
}
}
But the sounds is not playing at the same time of the lightning. Anyone to help me?