- Home /
Question by
TSSTUDIOS · Jun 15, 2014 at 04:54 PM ·
audioaudiosourceaudioplay
Function Update play sound once
public var acelerateSound: AudioSource; // its attached to refenrenced
function Update()
{
if(Input.GetAxisRaw("Vertical") > 0 || Input.GetKey (KeyCode.Joystick1Button2))
{
accelerate = true;
acelerateSound.Play();
}
else
accelerate = false;
}
Problem is, if i keep the key down the sound overlaps itself and i want it ust to play when i press the key for the first time
Comment
Best Answer
Answer by Josh707 · Jun 16, 2014 at 04:38 AM
When no buttons are held accelerate
will be false, you can play the sound only if it's false before setting it to true. As long as you hold the buttons down it will stay true, so it will not repeat.
if (Input.GetAxisRaw("Vertical") > 0 || Input.GetKey (KeyCode.Joystick1Button2)){
if (accelerate == false){
audio.Play();
}
accelerate = true;
}
else{
accelerate = false;
}
Your answer
Follow this Question
Related Questions
Audio Distortion effects? 0 Answers
Add Audio Source to a Prefab 2 Answers
2nd Audio Clip Not Playing 0 Answers
Need help with audio files causing unity to freeze 0 Answers
How Do I Get This To Play Sound? 0 Answers