• 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
Question by wayne57 · Oct 04, 2011 at 06:01 PM · audio

Audio Trigger Question

I made a scene with a type off animated train object going past the main char I would like to know whats the best way of making this animated object trigger a sound effect when it passes a certain point. I tried making a cube and placed it in the trains path with an audio source attached and sound. I clicked the make trigger button and attached a script but it didnt work. heres the script i got from the forums

function OnTriggerEnter (other : Collider)

{

audio.Play();

}

function OnTriggerExit (other : Collider)

{

audio.Stop();

}

thank you

wayne

Comment

People who like this

0 Show 0
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

  • Sort: 
avatar image

Answer by aldonaletto · Oct 04, 2011 at 06:26 PM

You may have two possible problems:
1- Your train isn't a CharacterController or Rigidbody, and thus isn't being detected by the trigger. If this is true, add a rigidbody to your train. If you don't use the rigidbody to anything else, disable Use Gravity and freeze all rotations and movements in Constraints (both in Rigidbody, at the Inspector) - this will avoid any disturbing physics reaction.
2- The audio source is too far from the audio listener (at the camera, usually), what fades the sound too much to be heard: it's better to attach the sound and the script to your train, in order to take advantage of the builtin roll off and Doppler effects (the trigger event is sent to the trigger and the object). Add an AudioSource and attach the above script to your train, then create your cubic trigger and size it to the covered area. Adjust the Roll Off curve and the Doppler effect amount to have a more compatible effect.

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Loading of audio clips on runtime fails on WebGL 0 Answers

2 Player Split Screen Racer Sound - Need more than one Audio Listener! 2 Answers

How can I add sound to this moving platform script? 0 Answers

Why Doesn't My Music Loop? 5 Answers

Synching audioclips over a network - why is this 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