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 SoBiT · May 20, 2013 at 12:02 AM · audiosounddragrigidbody

Play Sound When Opening Door

Hi, I've got a brilliant idea but I don't know how to do this.

I'd like to play a sound when open/close a door (by using the DragRigidbody.js). Dragging already works. My door is openable in an angle from 0-90°. Now I'd like to play a sound which depends on the current angle. So the sound is also played in the right speed.

I'll need to devide the duration of the sound with 90 and only play the part that is currently needed.

Easiest example: The sound duration is 90 seconds. If the door is rotated from 0-15 the sound plays 0-15 seconds

I hope this is understandable. Unfortunatly I think this will be hardly possible but some scripting genius will be able to give me a suggestion.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Rydrako · May 20, 2013 at 12:25 AM

First of all you must add an Audio Source to your door object. And whenever you rotate the door or want the sound to play call this in your script:

 audio.Play();

and when you want it to stop playing the sound:

 audio.Stop();

So you can edit the DragRigidbody script maybe like this:

 //New line after line 13
 audio.Stop();
 
 //Another new line after 64
 audio.Play();


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 SoBiT · May 20, 2013 at 12:29 AM 0
Share

Well, my question was not understandable then :D

I only want to play a part of the sound. I found PlayScheduled to do this.. maybe I'm able to get what I want.

I try to play the sound realtime. If the door gets opened very slowly, the sound also plays in the same tempo. If its opened very fast, the sound also plays very fast

avatar image
0

Answer by zagorskij · May 22, 2013 at 01:12 AM

ok your question is in fact definitely not easy.

PlayScheduled is a bti tricky, it was created more for sync reasons, to sync the start with an absolute time in that case with AudioSettings.dspTime. but you do not need this complication, you can use AudioSource.PlayDelayed , where the offset is specified in sec according to your clip.

About the tempo..well it's not easy task, to do it properly. Actually Unity does not let you to change ONLY tempo of a clip without changing the pitch, this is done for performance reasons. So you can work with AudioSource.pitch , it will change the tempo too, faster for values > 1, slower < 1, but it will change the pitch too, probably for a noise is not so dramatic, but try with voices :) if you don't like the result, you need to work with GetData and SetData, methods and playing chunks of the sound in sync with deltatime in your update methods, but this mean you need to manage pratically all the complexity of working with low level sound data

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

14 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

Related Questions

5.1 Channels is backwards in unity (non 3D) 0 Answers

Audio Settings Menu 2 Answers

play sound when moving stop sound when not 1 Answer

Making sounds wait for each other to finish 2 Answers

Unity wont play audio in editor, but will when the game is built. 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