- Home /
Audio Issue, Plays with PlayOneShot but not Play
So my last question, I kind of fixed but the fix is only working for my Player not the enemies. I need a solution that works across the board.
For some reason, the enemy audio isn't playing when using
audio.Play(); but plays audio.PlayOneShot();
it's just that it sounds like it's either playing the audio twice at the same time or that audio gets stuck some.
Below is the section of the code I'm using that has to do with the steps leading to the audio playing.
AudioSource audio; public AudioClip eSound;
private void Update() { if (eLife <= 0) { eDeath(); }
if (isSinking)
{
transform.Translate(-Vector3.up * sinkSpeed * Time.deltaTime);
}
}
void eDeath() { enemyAnim.SetBool("IsWalking", false); enemyAnim.SetBool("IsDead", true); //capsule.isTrigger = true; audio.clip = eSound; audio.PlayOneShot(eSound, 1); StartSinking(); } public void StartSinking() { agent.enabled = false; isSinking = true; Destroy(gameObject, 5f); }
The enemy is instantiated using a spawning point because I thought that the destruction of the asset was the issue since I originally just had the prefab in the scene standing there.
Please, help.
Small update, I tried removing and adding the audio source component. Coincidentally, I forgot to turn off Play on Awake so when I hit play, the clip played perfectly but when the enemy died, it had the issue. So I'm sure it's something within my code. If anyone would be so kind as to lend some assistance.
Your answer
Follow this Question
Related Questions
How to make my enemy stop moving once dead? 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do you make loop sounds exclusive to distance in C#? 1 Answer