New account registrations are disabed. This website is now an archive. Read more here.

Unity    Posted August 7, 2014 by Polraudio

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

 

Posted Image
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

Polraudio

  • Posted about 11 years ago

  • Engine
    Unity
  • Category
    Environment and Field Scripts
  • License
    Attribution 3.0 Unported
  • Version
    1.0

Stats

1,804 views

3 comments

Tags

n-a