No Javascript experience here so bare with me. I have a spacecraft, and need it to make an acceleration sound everytime it accelerates. The accelerate key is “z”, but I want the sound to stop when you let go of the “z” key.
So here’s the code I have but it’s not working, there is no sound whatsoever:
var sound : AudioClip;
function Update()
{
if (Input.GetKeyDown ("z"))
{
audio.PlayOneShot(sound);
}
else
{
audio.PlayOneShot(sound);
audio.Pause();
}
}
I attached an Audio Source to a empty game object, then applied the script to the empty game object with the correct sound specified.
One other issue is the spacecraft can also be controlled by a joystick. The acceleration key is “joystick button 1”, how can I trigger that sound by both the keypress AND joystick button?
Any help would be very much appreciated.