I wrote a script that plays a sound after 3 seconds and set it to play on awake which made it play right away. So I tried unchecking Play on awake it doesn’t play at all. Where is the error?
using UnityEngine;
using System.Collections;
public class Gunshot : MonoBehaviour
{
public AudioClip Gun;
private float volLowRange = .5f;
private float volHighRange = 1.0f;
private AudioSource source;
public float timeLeft = 5.0f;
void Awake()
{
source = GetComponent<AudioSource>();
}
public void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft <= 0.0f)
{
float vol = Random.Range(volLowRange, volHighRange);
source.PlayOneShot(Gun, vol);
}
}
}