Very simple stuff, on the code:
usingUnityengine;usingSystem.Collections; Public classParticle_ocean:monobehaviour { PublicParticlesystem Particlesystem; Privateparticlesystem.particle[] Particlesarray; Public intResolution = the; Public floatspacing =0.5f; Public floatNoisescale =0.2f; Public float[] Heightscale; Private floatPERLINNOISEANIMX =0.01f; Private floatPerlinnoiseanimy =0.01f; PublicGradient colorgradient; Public float[] Heighttogoto; Private floatHeightgotospeed =20f; Private floatHeightrestorespeed =2f; Public floatHeightgototime =1f; Public floatHeightrestoretime =0.1f; Public floatHeightclampmax =40f; Public floatHeightclampmin =4f; Public floatParticlesamplerate =0.05f; Private intFramecount =0; //Audio PublicAudiosource Audio; Private float[] spectrum; Public intSpectrumscale =60000; voidAwake () {application.targetframerate= -; } voidStart () {Particlesarray=NewParticlesystem.particle[resolution *resolution]; Particlesystem.maxparticles= Resolution *resolution; Particlesystem.emit (resolution*resolution); Particlesystem.getparticles (Particlesarray); Heightscale=New float[resolution]; Heighttogoto=New float[resolution]; Spectrum=New float[resolution]; Invokerepeating ("Updateheight",0, particlesamplerate); } voidUpdate () { for(inti =0; I < resolution; i++) { for(intj =0; J < resolution; J + +) { floatZpos = Mathf.perlinnoise (i * Noisescale + perlinnoiseanimx, J * Noisescale + perlinnoiseanimy) *Heightscale[j]; Particlesarray [i* Resolution + J].color = colorgradient.evaluate (Zpos *0.025f); Particlesarray [i* Resolution + J].position =NewVector3 (i * spacing, zpos, J *spacing); }} perlinnoiseanimx+=0.01f; Perlinnoiseanimy+=0.01f; Particlesystem.setparticles (Particlesarray, particlesarray.length); Gotoheight (); RestoreTo2 (); } voidUpdateheight () {audio. Getspectrumdata (Spectrum,0, Fftwindow.blackmanharris); for(intK =0; K < resolution; k++) {Heighttogoto[k]= Spectrum [K] *Spectrumscale; HEIGHTTOGOTO[K]=Mathf.clamp (Heighttogoto[k], heightclampmin, Heightclampmax); } } voidgotoheight () { for(intK =0; K < resolution; k++) {Heightscale[k]= Mathf.smoothdamp (Heightscale[k], heighttogoto[k],refheightgotospeed, Heightgototime); } } voidRestoreTo2 () { for(intK =0; K < resolution; k++) {Heightscale[k]= Mathf.smoothdamp (Heightscale[k], 2f,refheightrestorespeed, Heightrestoretime); } }}
Unity3d particle System + Audio Source = Music visualization