I’m trying to make a script where a gunshot goes off after a certain amount of time.
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);
}
}