hello I have developed a script to play a sound when the mouse is clicked. I have attached that script to an empty game object with an audio source with the sound that I want to play. However when I begin the game the sound plays and when I click nothing happens. I will post the script below and if anyone could help me that would be awesome. Thanks
var sound : AudioClip;
function Update () {
if (Input.GetMouseButtonDown(0)) {
GetComponent.<AudioSource>().PlayOneShot (sound);
}
}
The audiosource does not have looping selected
– supermudthis script is actually on a gameobject in your scene with an Audiosource component attached to it?
– NerevarHi, Can you add a Debug.Log into the if(){} to see if something happens when you click ?
– KdRWaylanderYes the script is attached to a gameobject in the scene with an audio component attached. And as regards for the debug.log, I start the scene and I hear the sound then when I click I see a debug.log message. Here is my updated script. Thanks for all the helps var sound : AudioClip; function Update () { if (Input.GetMouseButtonDown(0)) { GetComponent.<AudioSource>().PlayOneShot (sound); Debug.Log ("Hi"); } }
– supermud