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 ryisnelly · Dec 16, 2013 at 02:15 PM · audiocollisions

collision sounds

i have a chair that is animated and ends up hitting a wall, i have a box collider when the chair hits but the audio doesnt want to play, i have tried doing it a few ways but it wont work. any ideas? thanks

 #pragma strict
 
 var myClip : AudioClip;
 
 function OnTriggerEnter (other : Collider) {
 
  if(other.tag == "chair"){
   audio.PlayOneShot(myClip);
  }
 }
Comment
Add comment · Show 4
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 Tomer-Barkan · Dec 16, 2013 at 02:17 PM 0
Share

Do you have an audiosource attached to the object? Do you have an audiolistener enabled in the camera? Are you sure the code is executed (add Debug.Log inside the if statement)?

avatar image ryisnelly · Dec 16, 2013 at 02:37 PM 0
Share

yeah i have got both of them

avatar image ryisnelly · Dec 16, 2013 at 02:41 PM 0
Share

ive just tried it with Debug.Log and it was not logged

avatar image ryisnelly · Dec 16, 2013 at 02:52 PM 0
Share

if i change it change it to look for player as tag then it works

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by greencvbn · Dec 16, 2013 at 02:46 PM

if the chair is tagged in the inspector as a chair i do not see a problem but if the chair is the name of the object then change tag to name .disclaimer this could be wrong.

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 ryisnelly · Dec 16, 2013 at 02:49 PM 0
Share

it is definitely tagged as chair

avatar image
0

Answer by Tomer-Barkan · Dec 16, 2013 at 02:52 PM

Since it's not logging inside the if, either the collision is not triggering (try debugging outside the if to see if it logs) - in which case you have to make sure that one of the object has a rigidbody, both objects have colliders, the colliders are marked as trigger, and that they're 3d colliders and not 2d colliders.

If it is logging, then the problem is with the tag checking, the tag of the object you're colliding with might not be "chair".

Comment
Add comment · Show 4 · 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 ryisnelly · Dec 16, 2013 at 03:03 PM 0
Share

ive set it to a rigid body and now it works but only if it falls on the collider, if i try and freeze the y axis it does not work, any ideas? thank you

avatar image Tomer-Barkan · Dec 16, 2013 at 04:32 PM 0
Share

I have no idea what you are trying to do so you'll have to tell me more than just "falls on the collider". Describe your scene and your problem.

avatar image ryisnelly · Dec 17, 2013 at 01:40 PM 0
Share

ok, ive got a chair that is animated and when it finishes playing it hits in to the wall, and on that wall where the animation finishes is a box collider. i want a sound to play when the chair hits that box collider, if i make the box collider a rigidbody it falls through the map, but if i move the box collider above the chair and it falls on to the chair it makes the sound i want, but if i put it back in the position i want it and uncheck gravity or freeze the axis, the sound will not play. you with me now?

avatar image Tomer-Barkan · Dec 17, 2013 at 08:25 PM 0
Share

$$anonymous$$aybe it's better to add the rigidbody to the chair, and make it kinematic. That way it won't be affected by forces, but it will trigger collisions.

avatar image
0

Answer by O8PC · Nov 27, 2014 at 05:48 AM

is your wall a trigger? if it's not, than you might want to try this:

  #pragma strict
 var myClip : AudioClip;
     function OnCollisionEnter (other : Collider) {
          if(other.tag == "chair"){
          audio.PlayOneShot(myClip);
          }
     }


Comment
Add comment · 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

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

19 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

Related Questions

OnCollisionEnter Issues 2 Answers

Vehicle help 1 Answer

How should I make this Audio play? 1 Answer

Stream music in Unity mobile 0 Answers

Prevent items/player from going through walls/floor 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