- Home /
I want my Jump sound play one time when jumping
This my script : var sound : AudioClip; // drag the sound here
function Update (){
if(Input.GetButtonDown("Jump")){
// you can use PlayOneShot to specify the sound...
audio.PlayOneShot(sound);
// or you can define the sound in the Inspector
// and use Play like this:
audio.Play();
}
}
When I hit Space multiple times when jumping it makes multiple sounds but I want 1 sound for 1 jump ! Sorry for my bad english, I'm french.
Answer by PTerto · Oct 21, 2013 at 02:10 PM
Why don`t you do this, create a boolean that is true while the player is touching the terrain, and false if it isn't, so change this
function Update (){
if(Input.GetButtonDown("Jump")){
// you can use PlayOneShot to specify the sound...
audio.PlayOneShot(sound);
// or you can define the sound in the Inspector
// and use Play like this:
if(Variable)
audio.Play();
}
}
but remender, you have to play the sound before adding the force for the jump, while the player still on the ground ;D
But I don't know how to create this boolean, i'm a beginner :/
use this function: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html into this you have to verify if the collision is whit the terrain, if it is set Variable = true;
else variable = false ;D
Your answer
Follow this Question
Related Questions
Impact Sound When Jumping? (JavaScript) 1 Answer
Jumping sound not working after respawning 1 Answer
I want my Jump sound play one time when jumping 1 Answer
Character does not jump 1 Answer
How do I make realistic jumping? 0 Answers