C
C#15mo ago
mxshiiツ

❔ unity footstep sound sys

ok so i am trying to make footsteps variance like adding grass footstep sfx and stone footstep sfx and so on
Collider coll;
public PhysicMaterial grass;
public PlayerSoundSys sounds;

void Start()
{
coll = GetComponent<Collider>();
}

private void OnCollisionStay(Collision collision)
{
if(coll.sharedMaterial == grass)
{
sounds.FootStepSoundPlayGrass();
}
}
Collider coll;
public PhysicMaterial grass;
public PlayerSoundSys sounds;

void Start()
{
coll = GetComponent<Collider>();
}

private void OnCollisionStay(Collision collision)
{
if(coll.sharedMaterial == grass)
{
sounds.FootStepSoundPlayGrass();
}
}
but the sound just spams? also i added this script to an object and added animation events to the running animations can someone help?
5 Replies
Cattywampus
Cattywampus15mo ago
yeh, you need to check if the AudioSource is still playing or not
if (!audioSource.isPlaying)
//Do your thing
if (!audioSource.isPlaying)
//Do your thing
mxshiiツ
mxshiiツ15mo ago
its actually playing
Cattywampus
Cattywampus15mo ago
yeh, you'd need to check if it's playing then do nothing, otherwise, play so it won't re-playing in the middle Also for footsteps you want to add delays between sequence of playing the audio via https://docs.unity3d.com/ScriptReference/AudioSource.PlayDelayed.html to make it believable as footstep sound
mxshiiツ
mxshiiツ15mo ago
oh ok thx<3
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.