I created a laser sound I want to trigger when a projectile is fired. The projectile launches fine and there is no error when I play the scene but i still cannot hear the sound.
using System.Collections;
using UnityEngine;
public class ThrowObject : MonoBehaviour {
public GameObject projectile;
public AudioClip shootSound;
private float throwSpeed = 2000f;
private AudioSource source;
private float volLowRange = 0.5f;
private float volHighRange = 1.0f;
// Use this for initialization
void Awake () {
source = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1"))
{
source.PlayOneShot(shootSound, 1F);
GameObject throwThis = Instantiate (projectile, transform.position, transform.rotation) as GameObject;
throwThis.GetComponent<Rigidbody>().AddRelativeForce (new Vector3 (0, 0, throwSpeed));
}
}
}
For reference I am following this tutorial (Live Training 17th November 2014 - Sound Effects and Scripting - YouTube) and I am stuck at the 20:48 minute mark. Even after tweaking in the Inspector my sound still does not play.