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 |