• 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 santelia · Dec 21, 2011 at 10:10 PM · animationcollidertriggersound

animation and sound on collide

Hi, I am trying to open a door with its sound when the player (first person controller) enters a box collider. I have a door object with a large box collider, with "is trigger" checked. I have a simple animation called "door_animation_1", created in Unity with Wrap mode set to Once, and attached to the door object. I have a sound called "door_open" attached to the door object, with all the checks unchecked (no mute, no bypass, no play on awake, no loop).

I have a script attached to the door object, to play the door animation, with the following code:

 var myAnimation : AnimationClip;
 function OnTriggerEnter(other : Collider){
     animation.clip = myAnimation;
         animation.Play();
 }


and a second script to play the sound, always attached to the door object, with the following code:

 var myClip : AudioClip;
 function OnTriggerEnter(other : Collider){
      audio.clip = myClip;
      audio.Play();
 }

Of course in the door object properties the play animation script properties have the "My Animation" variable set to "door_animation_1", and the play audio script properties have the "My Clip" variable set to "door_open".

When the player (FPC) enters the box collider, the door opens and disappears, and no audio plays.

Can anyone figure out what my mistakes are and how can I solve this simple task? Thank you!

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
0

Answer by Beriss · Dec 22, 2011 at 08:26 AM

Hi, AudioClips are referenced and used by AudioSources to play sounds. To use the sound must define AudioSource.

http://unity3d.com/support/documentation/ScriptReference/AudioClip.html

http://unity3d.com/support/documentation/ScriptReference/AudioSource.html

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Detect if out of trigger 2 Answers

Play Sound on trigger 2 Answers

Play sound on trigger, sound is coming from the trigger 1 Answer

How to make audio play when passes a collider 2 Answers

Animation Script not working. 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