Hey,
looking for some help in implementing different noises depending on whether the zombie is idle, chasing, attacking, or dying. I want the sounds to be able to loop when audio is done, and transition when enemy state changes.
so far, I have created a Enemy Audio controller with the following, as well as altered the EnemyAI with some state public bools.
public class ZombieAudioController : MonoBehaviour
{
[SerializeField] AudioClip zombieIdleSFX;
[SerializeField] AudioClip zombieEnagedSFX;
[SerializeField] AudioClip zombieAttackingSFX;
[SerializeField] AudioClip zombieDyingSFX;
AudioSource audioSource;
EnemyAI enemyAI;
bool isIdle = false;
void Start()
{
audioSource = GetComponent<AudioSource>();
enemyAI = GetComponent<EnemyAI>();
}
// Update is called once per frame
void Update()
{
if (isIdle == true)
{
audioSource.PlayOneShot(zombieIdleSFX);
}
if (enemyAI.isChasing == true)
{
isIdle = false;
audioSource.PlayOneShot(zombieEnagedSFX);
}
if (enemyAI.isAttacking == true)
{
audioSource.PlayOneShot(zombieAttackingSFX);
}
if(enemyAI.isDying == true)
{
audioSource.PlayOneShot(zombieDyingSFX);
}
}
}
When I play, the effect works, but the initial idle audio gets played every frame. but when it transitions, the idle sound continues, and the chasing audio only plays once and repeats correctly. same for the attacking audio. Can someone give me some help on this?