- Home /
Question by
mpke · Mar 13, 2020 at 02:21 PM ·
character controllerfootsteps
Adding Footsteps do FPS Character Controller
Hi there!
I'm having issues do add footsteps to my FPS Character Controller. How can a add Jump and run?
I have this code so far:
public class FootSteps : MonoBehaviour {
public AudioClip walkSound;
public float footstepDelay;
private float nextFootstep = 0;
void Update () {
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S)
|| Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.W)) {
nextFootstep -= Time.deltaTime;
if (nextFootstep <= 0) {
GetComponent<AudioSource>().PlayOneShot(walkSound, 0.7f);
nextFootstep += footstepDelay;
}
}
}
}
Comment
Answer by unity_980059274 · Apr 23, 2020 at 08:15 PM
if you have ai in your character and you have a line about jumping create a audiosource and reference it like this: public AudioSource jumpSound; void Start(){ jumpSound = GetComponent<AudioSource>(); }
jump code here:
then in between the jump code put: 'jumpSound.Play();' ,if your character has a ai script that makes it move you can add a audio sound to play when you jump and for the running just make the footsteps faster