- Home /
Audio for movement
Hello
I have found this script for giving my 2d character sound for when it walks, although it does not have any legs it moves on a ball. I was wanting sound for just when you press the D or A keys, also if there is a way to add a jumping sound for when you press SPACE bar that would be cool as well. Also if anyone knows what I need to add for when the player gets hit that would also be sweet.
Here's the javascript
var audioStepLength = 0.3; var walkSounds:AudioClip[];
function Start () { var controller : CharacterController = GetComponent(CharacterController);
while (true) {
if (controller.isGrounded && controller.velocity.magnitude > 0.0)
{
audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
audio.Play();
yield WaitForSeconds(audioStepLength);
}
else
{
yield;
}
} }
Thanks
Answer by Nicolaj Schweitz · Apr 14, 2010 at 11:37 AM
Without stealing your learning:
Check out the 2D Gameplay Tutorial. It basically explains all you need to know when working with 2D platform games in Unity.
Here's a hint for you:
Left/Right is the horizontal axis when working with Input.GetAxis. These are also mapped to A/D, but that depends on the settings in Edit : Project Settings : Input.
You might also want to check out how the character controller works.
Cheers.
Your answer
Follow this Question
Related Questions
Tweaking character movement 1 Answer
How to make my object go in the direction its facing [C#] 3 Answers
Charactercontroller won't go down, only goes up 0 Answers
How do I script movement for my player? 1 Answer
Should character direction come from key press, or third person controller vector3? 0 Answers