• 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 Yordan · Feb 13, 2013 at 11:52 PM · collisionaudioclip

Change the music clip when crossing a cube border ?

Hello.

I have really stuck on the follow issue:

  • How to change the AudioSource clip when i am crossing trough a big box border ?

Comment
Add comment · Show 3
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 robertbu · Feb 14, 2013 at 12:50 AM 0
Share

I'm not sure what you mean by box. Is this a "physical" thing or just a defined area? When you say "i am crossing" are you talking about a mesh or the camera?

avatar image dubbreak · Feb 14, 2013 at 01:18 AM 0
Share

$$anonymous$$ore detail would help. What do you have so far (code wise)? Can you describe the scene?

avatar image Yordan · Feb 15, 2013 at 01:15 PM 0
Share

I mean - when i enter in specific area to start a specific music.. :)

1 Reply

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

Answer by dubbreak · Feb 15, 2013 at 04:58 PM

Here's a tutorial on trigger zones. It even has code to get you started.

Basically what you want is a box collider (you can have it on a cube if you want so you can see it during editing, but you most likely want to turn the renderer off for the game.. unless you want to see the box you are crossing into) and set the collider "is trigger" to true.

Is trigger will prevent it from acting like a physical box that stops you, but will still fire off a collision event (one specific for trigger called "OnTriggerEnter").

You'll still need to add your own code for checking it's the character that is coming into the border (or camera or whatever goes beyond the box border) then you simply play your audiosource clip (stopping your other one if need be.. various ways to do that depending on how you have your project set up).

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 Yordan · Feb 15, 2013 at 06:32 PM 0
Share

This is very good tutorial dubbreak, but If i set it up like this, then the character will not be able to pass trough the collision box. Any idea how to fix this ?

avatar image dubbreak · Feb 15, 2013 at 06:34 PM 0
Share

The collider being set to trigger should allow you to pass through. I'll do a quick test project to make sure.

avatar image Yordan · Feb 15, 2013 at 06:36 PM 0
Share

o ! I see ! THAN$$anonymous$$ YOU ! You really saved me a lot of nasty codding :)

avatar image dubbreak · Feb 15, 2013 at 06:37 PM 0
Share

So it works with that set to true?

avatar image Yordan · Feb 15, 2013 at 06:52 PM 0
Share

probably will. I am goin to experiment in a hour or so :)

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Adding sound javascript in unity2d 1 Answer

Playing an audio clip 4 Answers

Audio won't play on collision 0 Answers

Can play multiple sounds from one audiosource on an object. But cant play sound from audiosource on another? 0 Answers

OnTriggerExit stop audio 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