Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 RHD · Dec 05, 2014 at 11:59 AM · collisionsoundplay

repeated player collisions

I have found several ways to make a sound play when the guided object or player hits another object, but the sound only plays on the first hit. I have a number of object I want to play sound EVERY time they are hit by the guided object or player.

I have a script here which I like because it has the potential to trigger various sounds depending on the velocity of the hit, that I can figure out. But how can I get a sound to play EVERY time the object is hit and not just the first time? I have ploughed through Unity Answers but have not yet found one.

Thank you very much.

 #pragma strict
 
 var impact : AudioClip;
 
 function OnCollisionEnter (hit : Collision)
 {
    if(hit.relativeVelocity.magnitude >= 5)
    {
    audio.PlayOneShot (impact);
    }
 }

Comment
Add comment · Show 1
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 RHD · Dec 04, 2014 at 11:54 PM 0
Share

and I DID put the code in the correct window. Thanks

2 Replies

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

Answer by jenci1990 · Dec 05, 2014 at 12:59 PM

 #pragma strict
 var impact : AudioClip;
 
 function OnCollisionEnter (hit : Collision) {
     if (hit.relativeVelocity.magnitude >= 5) {
         AudioSource.PlayClipAtPoint( impact, transform.position);
     }
 }
Comment
Add comment · Show 1 · 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 RHD · Dec 05, 2014 at 01:14 PM 0
Share

Thanks that works perfectly and I can set up several variables to play a louder noise the harder the hit! Brilliant!

avatar image
0

Answer by FirePlantGames · Dec 09, 2014 at 04:43 PM

Don't post a comment as an answer (It's frowned upon by the unity admin mechs) and also accept the answer...

Comment
Add comment · Show 2 · 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 RHD · Dec 09, 2014 at 04:48 PM 0
Share

the rules on using Unity answers are so confusing that I really dislike using it. Any site that needs a video to explain what you are supposed to do is badly designed. I am completely at a loss as to why we can't all just talk to each other without constant harassment about breaking some rule that doesn't make sense in the context of the thread. It makes it really hard to understand other peoples threads when the answers and the questions don't relate to each other.

avatar image tanoshimi · Dec 09, 2014 at 05:25 PM 1
Share

"It makes it really hard to understand other peoples threads when the answers and the questions don't relate to each other."

UA "threads" do not operate like a discussion forum. They each start with a single, specific technical question, and then people propose different possible answers. When one of those answers solves the problem, the original poster should mark it as the correct solution. That way, anyone facing a problem in the future needs only to search whether the question has already been asked and, if so, simply looks up the accepted answer.

For this system to work, the only time you hit the "Post Answer" button should be when you are attempting to solve the original question. Any additional information/queries/requests for clarification should be posted as "Comments" under the respective answer/question. And, importantly, questioners must mark the answer that actually solved their problem by clicking the tick mark next to the appropriate answer...

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Play sound on collision 1 Answer

only one onCollisionEnter event is detected 1 Answer

Play An Audio Clip When An Instantiated Object Collides 1 Answer

Play sound on collision doesnt work 3 Answers

loop animation while audio is playing 0 Answers


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