Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jjey225 · Oct 31, 2019 at 10:49 AM · collisionparticlessoundsound effectsparticle-system

Sound play in spot of particle collision

Is there any way to create sound where particles of Particle System collides? Well, when a single particle comes into contact with the environment, it will be destroyed and a new one appears that should play the sound.
alt text alt text

I create such a script responsible for playing audio - it is pinned to the 'Spark' object:

 public int lastParticleCount = 0;
 
 // Use this for initialization
 void Update()
 {
     int newParticleCount = this.GetComponent<ParticleSystem>().particleCount;
     if (newParticleCount > lastParticleCount) {
         this.GetComponent<AudioSource>().PlayOneShot(GameObject.Find("Player").GetComponent<SoundManager>().sfxEmit[Random.Range(0, GameObject.Find("Player").GetComponent<SoundManager>().sfxEmit.Length - 1)]);
     }
     lastParticleCount = this.GetComponent<ParticleSystem>().particleCount;
 }


cap48359.png (1.1 kB)
cap48361.png (14.5 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by xxmariofer · Oct 31, 2019 at 12:31 PM

i have not tested, but what i would do is use the https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html on particle collision event, in which you receive a reference to a game object, and you can play the collision on the position of that object but i am not sure how precise it will be since you receive the gameobject that collides rather than the collision so you cant get the collide contact point but something like this would be my very first approach

     public AudioClip yourClip;
     void OnParticleCollision(GameObject other)
     {
         AudioSource.PlayClipAtPoint(yourClip, other.transfor.position);
     }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jjey225 · Nov 01, 2019 at 08:39 AM 0
Share

This is not what I mean - because now I gets objects that are floor or wall. If the returned GameObject were these particles it would be ok but it is not. I would need a position where the collision itself occurs, not the position of the object with which it interacts.

avatar image Reedex jjey225 · Nov 01, 2019 at 09:49 AM 0
Share

perhaps he means this:

     public AudioClip yourClip;
     void OnParticleCollision()
     {
         AudioSource.PlayClipAtPoint(yourClip,transform.position);
     }

avatar image xxmariofer jjey225 · Nov 01, 2019 at 12:54 PM 1
Share

You can get a reference to the particle system itself, use getcollisionevents to get the collisions between the object and the particles

 int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);

And iterate over the collisions for getting the intersection

 Vector3 pos = collisionEvents[i].intersection;

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

177 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Particle collision problem 0 Answers

Play sound from particle 1 Answer

Collision of particles with the box collider 2d does not work if the box collider 2d with the trigger checkbox marked 2 Answers

Dice roll collision sound 1 Answer

synchronized sound on collision script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges