- Home /
Footstep Sound Effect
Hi there,
I am fairly new to Unity and I am trying to add a footstep sound effect. I am following along to this video: https://www.youtube.com/watch?v=dexva26wOzg. What I have is the following:
#pragma strict
var Steps : AudioClip[];
private var isWalking : boolean = false;
private var controller : CharacterController;
function Awake()
{
controller = GetComponent(CharacterController);
}
function Update()
{
if(controller.velocity.sqrMagnitude > 0.15 )
{
isWalking = true;
}
else
{
isWalking = false;
}
}
InvokeRepeating("Walking", 1.0, 0.6);
function Walking()
{
if(isWalking)
{
AudioSource.PlayClipAtPoint(Steps[Random.Range(0,Steps.length)],gameObject.transform.position);
}
}
I do have the Audio Source component. Under Foots(script)>Steps, the Size is = 1 and Element 0 is a correct WAV audio file. Any help would be appreciated. Thanks!
Are you getting any sound at all? It looks like you are trying to play the sound clip from a random starting position within the clip. $$anonymous$$aybe you should try AudioSource.Play(). Check out the survival shooter tutorial on Unity there is some code in the Player and Enemy health scripts that may be useful.
The problem is I am not getting any sound at all. I tested the script and it works all the way until line 30.
$$anonymous$$ake sure that your sound is not a 3D sound if that's not what you want. (select the sound in the Project Pane, and check/uncheck "3D sound" in the inspector).
If you have a 3D sound and that's what you want, make sure the listener is close enough.
Also check if you have an Audio Listener (usually on the main camera).
Your answer
Follow this Question
Related Questions
Adjusting system audio levels... Please help! 1 Answer
Terrain texture specific step sounds? 1 Answer
Play sound when out of ammo 0 Answers
change detail in game an the sound? 3 Answers
I have problems with coding 0 Answers