- Home /
Question by
rayith · Feb 21 at 01:53 AM ·
charactercharactercontrollercharacter movementfootsteps
foot step sound
I want when my Character Controller is playing I want trigger the audio source to play the foot step sound and stop when not playing
this the code I have but its not triggering the sound, no error codes but no sound ether
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class footstep : MonoBehaviour
{
CharacterController cc;
void Start ()
{
cc = GetComponent<CharacterController>();
}
void Update()
{
if(cc.isGrounded == true && cc.velocity.magnitude > 2f && GetComponent<AudioSource>().isPlaying == false)
{
GetComponent<AudioSource>().volume = Random.Range(0.8f, 1);
GetComponent<AudioSource>().pitch = Random.Range(0.8f, 1.1f);
GetComponent<AudioSource>().Play();
}
}
}
Comment
Your answer