- Home /
I want to play an Audio Sound for a character while running.
I want to play an audio file while a key is being pressed and it must loop that audio file until the key is not being pressed anymore. For example while i am running when i press LeftShift it must play the audio and keep playing it until i am not running or not pressing leftShift anymore here is the code
public AudioSource Run;
void Start () {
}
void Update () {
if (Input.GetKeyDown (KeyCode.LeftShift))
Run.Play ();
else
Run.Stop ();
}
Have you set the audio clip to play ? https://docs.unity3d.com/ScriptReference/AudioSource-clip.html
Have you set the loop value to true ? https://docs.unity3d.com/ScriptReference/AudioSource-loop.html
yes i have, i have tried both of them and i get the same result, the running sound plays for a second and then it just stops or it keeps on playing even after i have stopped running.
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Can't jump in C# 1 Answer
audio doesn't play on movement 0 Answers
Children must not flip with parent. 3 Answers
Can't change the speed of a character. 2 Answers