- Home /
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 ?
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?
$$anonymous$$ore detail would help. What do you have so far (code wise)? Can you describe the scene?
I mean - when i enter in specific area to start a specific music.. :)
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).
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 ?
The collider being set to trigger should allow you to pass through. I'll do a quick test project to make sure.
o ! I see ! THAN$$anonymous$$ YOU ! You really saved me a lot of nasty codding :)