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 Michael 12 · Mar 04, 2011 at 07:38 PM · animationsounddoor

How do I add sound to a sliding door animation?

I could not find an answer to this anywhere.

I have an animation done in Unity's animation editor of two doors that slide open when I get close to them using raycast, how can I get my doors to play a sound effect when they are openning?

I don't know if you need to see it but this is my door code:

enum DoorStates {open, closed}; var doorState : DoorStates;

function Awake() { doorState = DoorStates.closed; }

function Update () { }

function Open() { animation.Play("PwrStationDoorsOpen"); doorState = DoorStates.open;

}

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

Answer by FLASHDENMARK · Mar 04, 2011 at 09:24 PM

enum DoorStates {open, closed}; var doorState : DoorStates; var doorSound : AudioClip;

function Awake() { doorState = DoorStates.closed; }

function Update () { }

function Open() { animation.Play("PwrStationDoorsOpen"); audio.PlayOneShot(doorSound); doorState = DoorStates.open;
}

The only thing you really have to do is to add a variable(var) called something like:

var doorSound : AudioClip;

//And when you open the door:

audio.PlayOneShot(doorSound);

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 Michael 12 · Mar 05, 2011 at 01:11 AM 0
Share

I understand some of this but what would I put in the "Something happend" I need and example ;)

avatar image Michael 12 · Mar 05, 2011 at 01:49 PM 0
Share

I tried Answer 2, it works but my sound seems to play when the door animation is finnishing for some reason.?

avatar image Michael 12 · Mar 05, 2011 at 02:05 PM 0
Share

O$$anonymous$$ Problem solved, what I did was find an mechanical door sound that starts sooner, the other sound I was using had a slight delay at the beginning. $$anonymous$$y other option which I think would have worked also would have been to change the start time of my door animantion. In any event it's working peachy keeno now lol

avatar image FLASHDENMARK · Mar 05, 2011 at 03:17 PM 0
Share

I am glad that it worked out for you :)

avatar image
0
Best Answer

Answer by efge · Mar 04, 2011 at 09:24 PM

You could use AudioSource.PlayOneShot inside your function open(), but when you want to avoid overlapping sounds you should use AudioSource.isPlaying.


Edit:

When you call PlayOneShot and animation.Play at the same time (like in OrangeLightning's answer) they should "play" together. If you want more control or an exact start time you could use Animation Events.
Take a look at the reference: Using Animation Events

Comment
Add comment · Show 3 · 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 Michael 12 · Mar 05, 2011 at 01:10 AM 0
Share

I tried this but the sound seems to play when the door is open but I need it to play as the door is opening as they are sliding doors, I hope I explained that right ?

avatar image Statement · Mar 05, 2011 at 11:13 AM 1
Share

It sounds to me your sound clip have some silence in the beginning (no pun intended).

avatar image Michael 12 · Mar 05, 2011 at 01:45 PM 0
Share

That could be the the case you know, I was listenning to it closly and it does seem to start a little slow, I began searching for someway to see if I can start of the sound playing a bit sooner but I could not find anything in the reference guide on that.

I was also toying with the idea of having a box collider triger the sound sooner but that might seem kind of odd if the player walked through the box accidentally not intending to go through the door.

Baring all of that I might just have my sound placed wrong??

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

FPSController Collision with moving objects 2 Answers

Object gone aftar play - Animation problem. 0 Answers

Animate Doors and Button Through Script 1 Answer

Door animation after press a key 2 Answers

Animation clip does not exist? 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