Adding a debug line


I recently made a script for playing audio with a trigger but it doesn’t play and I think adding a debug line would fix the prob but I don’t know how to add a debug line XD . Can i get some help?


Not entirely sure what you mean by a “debug line” even less sure how anything I can think you might be referring to would fix the issue, but could help you work out what the issue is. Did you mean a breakpoint? or a Debug.Log() message?

In any case, regarding the issue of your audio not playing. First of all, what behaviour are you looking for, click button, sound plays, or sound plays “whilst” the mouse button is down?

If the first, then you want to use GetMouseButtonDown as what you currently have will trigger repeatedly (and repeatedly calling play each frame will keep restarting your audio, making it unlikely to be heard until you then release the mouse button and the last Play call can actually run out).

If the second, the similarly, you don’t want to call play repeatedly, as you’ll not hear the sound, so you want to only call play if it is not already playing (IsPlaying property on AudioSource for this one).