Unity
Audio Trigger
Introduction
This script will play an audio clip when an object enters its area.
Features
-Plays audio clip on trigger
-Audio stops playing when you leave the area
The Code
License Terms
Attribution 3.0 Unported - You must attribute the work in the manner specified by the author or licensor. Commerical use allowed.
Frequently Asked Questions
Q: Its not working WTF!?
A: Some reason it only works with 3d colliders. You also need to make sure you have a collider set for trigger.
Q: Can this work with 2D?
A: At the moment i dont know why it doesnt. You can get it to work with 2d objects by having a 3D collider for both objects colliding.
Instructions
-Attach the script to an object you want as the audio trigger.
-Add a 3D collider to the object
-Add a blank audio source
1: What audio clip to play
2: Tag of the item to trigger the audio. Defaults to Player.
3: The Trigger
4: The blank Audio Source
Author Notes
To Do:
-Toggle for stopping music upon leaving the trigger area
Compatibility
Doesnt work with 2D colliders for some reason.
Version History
1.0 – Release
Credits & Thanks
Polraudio – Dont need to add to credits
Comments (3)
Leave a Reply
You must be logged in to post a comment.
ShinkuAura
How many scripts are you working on?
Polraudio
So far just these 2. Trying to think of other things that will be useful. Since theres no real default stuff like there is RMXP its hard to find stuff to script that will be useful for everyone and usable by everyone.
zahraa
WOW! I can't wait to try Unity and apply your scripts! It sounds super interesting!