![]() ![]() A simple Debug.Log function call is enough to determine this. You must make sure that the Play code is even executing. Don't deactivate the AudioSource GameObject. If the GameObject that has the Audiosource is deactivated, the audio would also stop. Or you can play the Audio, wait for it to finish playing then destroy it: IEnumerator playAudio()ĥ.The GameObject the AudioSource is attached to has been deactivated. The fix is to attach the AudioSource to GameObject that doesn't destroy. ![]() ![]() If the GameObject the AudioSource has been attached to is destroyed, the Audio would not play. This mistake is not uncommon and it causes the AudioSource not have time to play the audio over and over again.Įxample of this mistake: private void Update()Ĭheck the Audio is playing first before playing it.(Did this in the code from this question which is correct!) private void Update()Ĥ.The GameObject the AudioSource is attached to has been destroyed. Check and disable the mute on the Editor.ģ.Playing the sound every frame. If the Editor is muted no sound will be coming out of it but the build should have a sound. Sometimes, the audio reference is lost so simply repeat this step again to recreate the reference.Ģ.Editor is muted. Simply drag the audio to your hurtSound slot and you should hear the sound. If hurtSound not assigned or initialized in the Editor or via code, Unity won't throw any error. This is your AudioClip public AudioClip hurtSound Reasons why audio won't play in Unity: (From likely to unlikely) Your sound won't play not because you put it in the Update function.The reason it's not the Update function like some mentioned is because you protected it with if (!soundSource.isPlaying) so it will only play again only when the first one is doe playing. There are just many reasons why Audio many not play in Unity. I can't get it to play the sound it sees the audio source but my If 2D game, use OnCollisionEnter2D instead. Use collision detection + collider instead of the Update function to detect the hit then play audio: void OnCollisionEnter(Collision collision) I am trying to program a script that when you hit an enemy it plays a ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |