After beating my head against the wall trying to find something about this on the forum, I’ll have to post a new note: I need to loop a sound clip only for as long as a given action occurs (in this case, while one of the baddies is within a certain range of the player), rather than looping the entire clip for an infinite period; and I need it to smoothly fade in and out at the beginning and end of that period. Unity doesn’t seem to have any built-in way to do this (unless I just repeat a series of very short clips for the duration of the action, but in my case that isn’t going to work very well). What are my options?
If you’re not using a sound library that might help out with common needs like this then you’ll have to manually handle it yourself using coroutines or other update-based methods.
To build this stuff you can write fairly simple wrappers with your own tweening code, or use one of the popular tweening libraries to help out. You’ll end up playing a clip on an audiosource and with a reference to the audiosource adjusting the volume for fadeins and fadeouts as needed. When the volume fades down to 0 you could stop the audiosource playing and possibly return it to a pool or something for reuse if you need to. You could also make use of the various audiosource play methods that schedule the time to play clips based on the dsp timing, depending on what your game needs to do and how complex the sound effects are. Maybe take a look at something like SoundKit (GitHub - prime31/SoundKit) for some inspiration.
Unfortunately, Unity does not have native support for things like internal loops within clips, so you can’t have a single sound that has a start, a loop, and an end. Some external libraries can handle this sort of thing too (eg. Fabric).