- Home /
Question by
MR_STUTTER · Mar 16, 2013 at 05:32 AM ·
javascriptaudio
Im having trouble with my Audio playing on a Mouse Click. Tell me what is wrong with my Script?
@script RequireComponent(AudioSource)
var front : AudioClip;
var back : AudioClip;
function Update(){
if (Input.GetMouseButtonDown(0))
{
audio.PlayOneShot(AudioSource.front, 1.0);
}
if (Input.GetMouseButtonDown(1))
{
audio.PlayOneShot(AudioSource.back, 1.0);
}
}
Comment
Best Answer
Answer by gribbly · Mar 16, 2013 at 06:16 AM
Assuming "front" and "back" are assigned in the inspector, you don't need the "AudioSource." prefix:
if (Input.GetMouseButtonDown(0))
{
audio.PlayOneShot(front, 1.0);
}
Answer by MR_STUTTER · Mar 16, 2013 at 07:00 AM
NEVERMIND GUYS. I FINALLY FIGURED IT OUT. I just needed to erase the AudioSource from the AudioSource.front and AudioSource.back and it was all good.
Your answer
Follow this Question
Related Questions
Audio not playing [Fixed] 1 Answer
Play sound when out of ammo 0 Answers
How i make this code in Unity Javascript 2 Answers
Audio is repeating. 3 Answers
On Mouse Click Play Sound 1 Answer