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 metalmutha11 · Mar 24, 2012 at 05:11 PM · triggersoundcube

Trigger sound when walking through cube trigger

hi guys, all i want to do is have a specific sound triggered when i walk through a box with the trigger setting on. I have searched hard for this and found many answers but i just cant seem to implement it in my scene! :(

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by reptilebeats · Mar 25, 2012 at 12:31 AM

if i understand right all you want is a sound to play on trigger this is very simple all it is

function OnTriggerEnter(){

audio.Play(); }

or if the audio is on another object use gameObject.Find("other").audio.Play();

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
avatar image
0

Answer by DaveA · Mar 24, 2012 at 05:23 PM

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

Comment
Add comment · Show 5 · 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 AlucardJay · Mar 24, 2012 at 05:30 PM 0
Share

sry Dave, but here's the whole script even :)

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

avatar image metalmutha11 · Mar 24, 2012 at 06:00 PM 0
Share

cheers for the quick reply! :) sadly this is the one i have tried countless times. i throw it into the javascript editor, then throw that into the cube and it appears in the inspector panel. once i have done that i throw in the audio file to the script in the inspector then play, walk through the cube and still no sound :(.

would the type of audio format be a problem?! they are .wav files

avatar image AlucardJay · Mar 24, 2012 at 06:18 PM 1
Share

maybe the the sound IS playing, but your audio listener is too far away for you to hear it ?

http://unity3d.com/support/documentation/Components/class-AudioListener.html

OR , do you have an Audio Source attached to the gameObject that the play script is attached to ?

http://unity3d.com/support/documentation/Components/class-AudioSource.html

Create an Empty gameObject, give it the component Audio Source (untick play on awake, and leave the audio clip box at None / empty). Then apply the script. (Don't forget to add the sounds to the prefab / object in the inspector after you have attached the script and component audio source).

From another answer I gave : http://answers.unity3d.com/questions/210047/questions-about-sound.html

avatar image metalmutha11 · Mar 24, 2012 at 11:03 PM 0
Share

still does not work for me, tried them all :( everything looks like it should work! this is tre annoying, will have to give up have been trying to figure this out for a good 28 hrs to no avail. thanks anyway

avatar image AlucardJay · Mar 25, 2012 at 03:01 AM 0
Share

that is so bizarre dude ....

@$$anonymous$$icheal Gray raises a good point :

OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider . http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

OnTriggerEnter is called when the Collider other enters the trigger . http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html

try some debugging. where you have the command to play audio => print("audio.Play CALLED"); see if you are getting a message in the console when the sound is meant to be played.

avatar image
0

Answer by Himo · Mar 29, 2012 at 04:09 PM

I found that when you apply the code to the first person controller the steps you have to untick the play on awake box and then apply the code to the first person controler. Maybe this will help?

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sound On Collision Not Working 3 Answers

Best Technique For 3D Cube Map 0 Answers

Cant repeat Sound 1 Answer

Something wrong with destroying script 0 Answers

Wait until audio is finished before set active is false 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