I'm thinking that you could implmenent this by having a separate invisible GameObject in your scene which has an AudioSource attached (with the looped water sound clip assigned).
You'd then move this audiosource around to follow the player, but have it constrained to the shape of your water. The complexity of implementing this would then be directly tied to the complexity of the shape of your water.
For example, the easiest shape would be a circular pond or lake. In this case, you could use something like this pseudo-code to constrain the water audio object:
Similarly, a square or rectangular shaped area of water would be fairly simple:
If your water is more of an arbitrary shape, you'll need a more complex algorithm to determine how to constrain your audio object to the 2d surface of that shape. Perhaps some code which first finds the triangle in your water mesh which is nearest the player, and then some code which constrains the audio object to that triangle.
If your water is made using a large plane which intersects a terrain which dips below the water level in certain areas (as is a common technique), you'll need another method again, because this set-up doesn't readily reveal any data that you can use to determine the nearest area of water. One method that springs to mind to implement this would be to do a quick "scan" of your whole terrain using raycasts, to build up a low-res 2d grid of data representing "water" and "non-water" areas. Then, at runtime, you could have an algorithm which picks the nearest grid cell marked as water to determine the correct location for your audiosource. You'd also need to add some kind of blending between the positions to avoid the audiosource suddenly jumping from one cell position to another.
Anyway... food for thought, it's definitely an interesting question. Good luck!
answered Mar 16 '10 at 05:33 PM
I need this too and i think the most practical way would be to have a sound object follow the player around and stop at the edge of the water. idk how to do this, though. )= maybe a collider?
answered May 17 '10 at 01:34 AM
I'm going to answer it.
Make the aer a trigger, attach a sound to the player and make a script so when the player enters the trigger, the sound on the player activates.
answered May 17 '10 at 02:49 PM