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 Dungeon · Sep 07, 2013 at 01:01 AM · audiotrigger

Audio Trigger Problems

Hello. I have recently written (with help from another question (: ) a script that deactivates gameobjects when a trigger is hit (for a 3.X version of unity). I have added a sound and audio source to the object and added a play audio in my script. The audio does not play. Here is the script.

 #pragma strict
 var Item : GameObject;
 var Sound : AudioClip;
 function Start () {
 Item.active=true;
 
 }
 
 function OnTriggerEnter(){
     audio.PlayOneShot(Sound);
     Item.SetActiveRecursively(false);
 
 }
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 RyanZimmerman87 · Sep 07, 2013 at 01:25 AM

Have you assigned the sound file to both the Audio Source and Audio Clip in the inspector?

And are you sure the OnTriggerEnter() is working? You might want to set up some debug text to verify the event is working.

If you did all that right my only guess is that your SetActiveRecursively could be causing the problem. Or that your audio source is not set to be large enough to reach your Audio Listener.

You could try increasing the Audio Source "Min Distance" and "Max Distance" variables to ensure that your source will in fact reach your listener.

Also I have to ask why are you not using Unity 4.X?

They have changed the way the gameObjects are handled so SetActiveRecursively is no longer the way to go in 4.X maybe it's not that great in 3.X either?

You may also want to try it without the :

Item.SetActiveRecursively(false);

That could cause the sound to not play as well possibly, I've never used SetActiveRecursively though so I'm just speculating.

Comment
Add comment · Show 10 · 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 Dungeon · Sep 07, 2013 at 01:40 AM 0
Share

Honestly, i wish I could switch but I can't because I have a few other projects in progress that use SetActiveRecursively and, I have to have this game by tomorrow. Also, The OnTriggerEnter does work.

avatar image RyanZimmerman87 · Sep 07, 2013 at 01:46 AM 0
Share

Did you try all the stuff I suggested and still doesn't work?

avatar image Dungeon · Sep 07, 2013 at 01:58 AM 0
Share

What did you mean by my SetActiveRecursively?

avatar image RyanZimmerman87 · Sep 07, 2013 at 02:08 AM 0
Share

I mean you should try not using that to see if that is the problem. I'm trying to help you isolate the problem since I'm not sure what is causing it.

avatar image Dungeon · Sep 07, 2013 at 02:17 AM 0
Share

what should I use?

Show more comments

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

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

Related Questions

Trigger to play music needs to check if the same music is already playing 1 Answer

Play random sound on NPC when trigger enter 1 Answer

Cannot get trigger sound to play for collectibles 1 Answer

Script to trigger all audio playing to stop, and play a different audio? 1 Answer

GetComponent().Play(); Question(s) 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