- Home /
Audio Source Logic Error for foot steps
So I can get my game to run fine but I run into a problem with the audio. When i have two or more audio sources using the same function on different scripts and objects. The audio will either cut out completely or rapidly play the sound. Here is some of the code i used.
This function gets variables From a Game object that holds the list. Have not coded index changes because i want to reuse sound effects based on enumeration choices made in the inspector
public static void CharacterFileAssignment(DarkWorldCharacterBase darkWorldCharacterBase, ref FileDatabase fileDatabase, ref AudioSource audioSource)
{
SystemFiles systemFiles = GameObject.FindGameObjectWithTag("SystemObject").gameObject.GetComponent<SystemFiles>();
fileDatabase = systemFiles.dataBaseList[0];
fileDatabase.audioSource.clip = fileDatabase.footStep_Regular_Clip;
audioSource = fileDatabase.audioSource;
}
This Function is below assigns the audio Source code clips and also plays the audio source
//Namespace function to be used on Scripts
public static void CharacterSoundEffects(CharacterState characterState, StandState standState, MoveState moveState, FileDatabase fileDatabase, ref AudioSource audioSource)
{
if (characterState == CharacterState.StandingState && audioSource.isPlaying == true)
{
audioSource.Stop();
if (standState == StandState.Idle)
{
}
else if (standState == StandState.Idle)
{
}
}
else if (characterState == CharacterState.MovingState && audioSource.isPlaying == false)
{
if (moveState == MoveState.Run && audioSource.isPlaying == false)
{
audioSource.clip = fileDatabase.footStep_Regular_Clip;
audioSource.Play();
//audioSource.loop = true;
}
if (moveState == MoveState.Walk && audioSource.isPlaying == false)
{
audioSource.clip = fileDatabase.footStep_Regular_Clip;
audioSource.Play();
//audioSource.loop = true;
}
}
I have no Idea what i am doing wrong. Any help would be gravy;
Your answer

Follow this Question
Related Questions
Terrain into Model 0 Answers
Is there a way to toggle between active characters via a GUI? 0 Answers
C# How to access gameObject in main thread 0 Answers
High quality renders- getting rid of moire 0 Answers
Having trouble with grid movement 1 Answer