- Home /
Question by
cariaga · Dec 11, 2011 at 09:35 AM ·
triggeraudiolisteneraudioplaysource
audio playback problem not being triggered
var ButtonSpace: AudioClip;
var setTrigger : boolean = false; function Update () {
if (Input.GetKeydown (KeyCode.Space)&& !setTrigger) {
if (!audio.isPlaying) {
audio.loop = false;
setTrigger = true;
audio.clip = ButtonSpace;
audio.Play();
}
}
}
@script RequireComponent(AudioSource)
audio is not being played back when i press a key
Comment
Best Answer
Answer by aldonaletto · Dec 11, 2011 at 07:42 PM
It seems the problem is the Input.GetKeyDown - you've wrote Input.GetKeydown. You must be receiving runtime errors. Change the line to:
if (Input.GetKeyDown (KeyCode.Space)&& !setTrigger) {
There's something weird about this code: it will play only once, since setTrigger is set and nothing in the script reset its value. Is it an intended feature?
And what's this variable purpose? Enable sound when the player entered a trigger?
Your answer
![](https://koobas.hobune.stream/wayback/20220613061958im_/https://answers.unity.com/themes/thub/images/avi.jpg)