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 lukeylad118 · Feb 16, 2011 at 02:53 PM · collisionsound

HELP!!! Sound won't play upon Collision! Script looks correct...

Hi guys, This script below isn't working. I've just spent the last 2 hours trying to get it to work but it just isn't happening. My sound file has been converted to a .ogg file, and everything looks correct to me and I get no compile errors. Anyone see what's wrong?

I need it to play the sound when the player touches the object. I am using the FirstPersonControllerPrefab from IslandDemo.

Thanks in advance

var moon : AudioClip; // set this to your sound in the inspector

function OnCollisionEnter (collision : Collision) { // next line requires an AudioSource component on this gameobject audio.PlayOneShot(moon); }

Comment
Add comment · Show 2
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 · Feb 16, 2011 at 02:58 PM 1
Share

The first thing I'd recommend doing when you run into problems like this is to test that it's even getting to "OnCollisionEnter". Add a '`print("Inside OnCollisionEnter")`' debug message. If it appears, then there's problem with the audio playing (or being heard). If not, you have somewhere else to look. This sort of testing/debugging is usually much more revealing than scouring over your own code for hours. Hope this helps - please update your question with any findings, if you're still stuck!

avatar image Jessy · Feb 16, 2011 at 03:08 PM 0
Share

Also, keep the helpful hints from the manual in $$anonymous$$d: "If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations. Note that collision events are only sent if one of the colliders also has a non-kinematic rigid body attached."

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by StephanK · Feb 16, 2011 at 03:10 PM

I you are using the FirstPersonController there probably won't be a Collision Event. Try to use OnControllerColliderHit() instead of OnCollisionEnter.

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
avatar image
0

Answer by tylo · Mar 27, 2011 at 06:34 AM

There is a chart that explains which collision events will fire under certain circumstances.

There are actually three categories of "Colliders". Static (no rigidbody attached), Rigidbody , and Kinematic Rigidbody.

The chart explains under which circumstances each of these will fire.

You can view it here: http://unity3d.com/support/documentation/Components/class-BoxCollider.html

Scroll down to the bottom of the page.

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

1 Person is following this question.

avatar image

Related Questions

Making a sound using collisions 1 Answer

Sound on collisions 1 Answer

help sound on collision when key down 2 Answers

How to reproduce a sound when my character collide 1 Answer

Trigger respawn after collision? 3 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