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 Chrifoldus · Mar 31, 2010 at 09:02 PM · collisionterrainobjectsoundcollide

How can I make a sound deploy after colliding with a certain object (or terrain)?

Hi everyone. I was wandering if there was a way to make a sound deploy when hitting a specific object/terrain, because I really need it for a game that needs sounds, desperately.

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
4
Best Answer

Answer by Eric5h5 · Mar 31, 2010 at 09:37 PM

Check the name or tag of the colliding object in OnCollisionEnter, and play an appropriate sound depending on the results:

var funkySound : AudioClip; var enemyHitSound : AudioClip;

function OnCollisionEnter (other : Collision) { if (other.gameObject.name == "FunkyThing") { audio.clip = funkySound; audio.Play(); } else if (other.gameObject.tag == "Enemy") { audio.clip = enemyHitSound; audio.Play(); } }

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 Chrifoldus · Apr 01, 2010 at 03:58 AM 0
Share

Thanks but Could you help me with this? I still don't know how to work it.

avatar image Eric5h5 · Apr 01, 2010 at 05:10 AM 0
Share

@Chrifoldus: You're going to have to be a lot more specific than that.

avatar image Chrifoldus · Apr 01, 2010 at 06:51 AM 0
Share

I $$anonymous$$ean, I Just inserted the code and i select sound but nothing happens.

avatar image Eric5h5 · Apr 01, 2010 at 08:31 AM 0
Share

@Chrifoldus: I'd strongly suggest doing some tutorials and reading the docs so you understand how Unity works. If you used it literally, nothing will happen with the code I posted unless the object the script's attached to collided with a game object named "FunkyThing" or any object tagged "Enemy".

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

No one has followed this question yet.

Related Questions

Objects Touching? 1 Answer

Object collision with terrain 0 Answers

Camera Colliding with Terrain 1 Answer

Collision between objects 2 Answers

Object falling through terrain with script 2 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