var gunSound : AudioClip;
function Update ()
{
if (Input.GetButtonDown("Fire1"));
audio.PlayOneShot(gunSound);
}
Whenever I play, it plays the clip continuously in a long screech (not looping); I think it’s continuously triggered.
I’m trying to get an audio clip to play when I press down the mouse(Shoot). It could also work if it played whenever a prefab is instantiated.
I’m new to java, please help.
Thanks
First, javascript and java aren’t the same thing. Unity uses javascript.
Second, make sure the code you want executed in the if block is surrounded by brackets, like this:
function Update ()
{
if (Input.GetButtonDown("Fire1"))
{
audio.PlayOneShot(gunSound);
}
}
The way you had it, the PlayOneShot(…) call was happening each frame (hence the wierd noises).
Hope this helps!
Thanks to both.
Problem Solved!
JAVASCRIPT not java.
Got it.