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 JoBrindley · Jan 14, 2013 at 12:29 PM · triggersound

Sound stop when entering trigger

I have a sound playing from an object when gameplay starts, but I want the sound to stop when I enter the box collider (trigger) added to that object. Can anyone help me?

 var Sound:AudioClip;
 
 function OnTriggerEnter () 
 {
     audio.Stop(Sound);
 }
 

`

Comment
Add comment · Show 1
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 liszto · Jan 14, 2013 at 12:36 PM 0
Share

that kind of thing must work but the playing sound start with this script or another ?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Lovrenc · Jan 14, 2013 at 12:38 PM

Is your collision actually happening? Do this:

 function OnTriggerEnter (collision : Collision) 
 {
     Debug.Log("Collision! Stop playing audio.");
     audio.Stop(Sound);
 }

So check if collision happens. If not search for proper collision settings.

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 TheHoboCoder · Jan 14, 2013 at 06:36 PM

Are you sure this script is attached to same object where that AudioSource is? Because if not, then that is the problem.

If it is, then it should work. As Lovrenc mentioned, you could try if Debug.Log gives you any feedback.

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 JoBrindley · Jan 14, 2013 at 07:03 PM

Yer, the sound audio source is on the same object as the script What do you mean when you say Debug.Log?? I'm really new to all this stuff

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 Lovrenc · Jan 14, 2013 at 07:03 PM 0
Share

Use CO$$anonymous$$$$anonymous$$ENTS to comment!

I wrote the Debug.Log code below....

avatar image JoBrindley · Jan 14, 2013 at 07:06 PM 0
Share

oh yer, sorry. I've done that before :/ wasn't thinking. and yer, I tried that and it didn't work either.

avatar image Lovrenc · Jan 14, 2013 at 07:10 PM 0
Share

Its not ment to work. It shows you if you get a collision. Read some unity docs. And since you didnt get any message it means you didnt set up your player/objects correctly.

OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.

In contrast to OnTriggerEnter, OnCollisionEnter is passed the Collision class and not a Collider. The Collision class contains information about contact points, impact velocity etc. If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations. Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.

avatar image JoBrindley · Jan 14, 2013 at 07:13 PM 0
Share

ah, that would be why. Feel kinda stupid now. I've got a uni hand-in in 2 days, so will be properly trying to understand scripting etc after that. Thank you though :)

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

11 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

Related Questions

Trigger sound when pressing button 2 Answers

Loop Sounds when within trigger 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can anyone help me figure this script out? (Light Trigger) 1 Answer

A trigger is activating scripts of other triggers 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