audio - Unity3D Play sound from particle -


i trying play sound when particle collides wall. right now, plays sound parent object, player.

however, want sound play particle. means when particle far left, vaguely hear sound coming left.

is there way play sound particle, when collides?

you can use onparticlecollision , particlephysicsextensions, , play sound playclipatpoint:

using unityengine; using system.collections;  [requirecomponent(typeof(particlesystem))] public class collidingparticles : monobehaviour {      public audioclip collisionsfx;      particlesystem partsystem;     particlecollisionevent[] collisionevents;      void awake () {          partsystem = getcomponent<particlesystem>();         collisionevents = new particlecollisionevent[16];     }      void onparticlecollision (gameobject other) {          int safelength = partsystem.getsafecollisioneventsize();         if (collisionevents.length < safelength)             collisionevents = new particlecollisionevent[safelength];          int totalcollisions = partsystem.getcollisionevents(other, collisionevents);         (int = 0; < totalcollisions; i++)             audiosource.playclipatpoint(collisionsfx, collisionevents[i].intersection);          print (totalcollisions);     } } 

the problem temporary audiosource created playclipatpoint cannot retrieved (to set 3d sound). better off creating own playclipatpoint method instantiates prefab, configured 3d audiosource , clip want, , run destroy(instance, seconds) mark timed destruction.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -