ThunderClap

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?

Does the audio clip (the actual audio file of the thunder sound) play immediately when you listen to it normally? Taking unity out of the equation and only listening to the audio clip itself is there a delay before the Thunder?


I’m thinking that it could be the audio file itself that has a delay because the rest of your code looks fine. Assuming that you can hear it and it’s just not the right timing.