x


What is the script code on how to trigger a song for the player to Listen to?

What is the code for the player to collide with and trigger a music source to the player to hear as an Audio Source not at the current position. Because I am having difficulty making the player collide with the trigger and everything would work but there would be no direct sound for the player to listen to. SO if you could help I would really appreaciate it. ALOT!

more ▼

asked Feb 27 '10 at 01:08 AM

Trevor 1 gravatar image

Trevor 1
45 10 11 17

By "not at the current position" do you mean you want to trigger a sound somewhere else in the scene?

Feb 27 '10 at 01:33 AM JDonavan 1

Just a note: you don't need to post your question again if it isn't immediately answered, its still on the site so reposting it just kind of clutters.

Feb 27 '10 at 02:55 AM Jason_DB

Yes to where you first start off by not hearing any music play untill you reach a certain point of the level Music would start to play like if it were HALO or somethin.

Feb 27 '10 at 03:17 AM Trevor 1
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I am not sure if this is what you wanted but here is what i got out of it, I decided to add comments to make things easier for you.

// This is a public variable so you have to assign the audio clip you wish to play in the Inspector
    var HaloTheme : AudioClip;

    // Make a box, delete the mesh renderer, and make the Box Collider a trigger by selecting 'Is Trigger'
    // Then expand it to enclose the whole area you wish it to cover, ie a room.
    function OnTriggerEnter (other : Collider) {
    // Make sure your character is tagged 'player'
    if (other.gameObject.tag == "player") {

    // Plays the audio that you want...
            audio.Play(HaloTheme);
        }
    }

    // Simply makes it so the object can play audio
    @script RequireComponent(AudioSource) 

Also, i didn't put a comment in there for it, but on the Audio Source comopnet that is added, make sure you have it set to Loop, if you want it to loop that is.

Lastly, take a look at this for other Audio related scripting issues: Unity Scripting Reference: Audio Source

Hopefully i have helped out, good luck and have fun with Unity!!

more ▼

answered Feb 28 '10 at 04:13 AM

xToxicInferno gravatar image

xToxicInferno
485 24 28 41

(comments are locked)
10|3000 characters needed characters left

Not sure if I understand your question, but if you want to start a jukebox when a player is entering the room the only thing you have to do is attach a trigger collider to the jukebox that contains the room or area where the music should be heard. Then OnTriggerEnter start the AudioSource. If the clip attached to the AudioSource is marked as a 3d sound the music's level will depend on the distance of the AudioListener (probably attached to your cam/player) to the AudioSource. If you don't want that disable the clip's 3d sound property.

more ▼

answered Feb 27 '10 at 11:47 AM

StephanK gravatar image

StephanK
6k 39 53 93

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5093
x3807
x1880
x1030
x171

asked: Feb 27 '10 at 01:08 AM

Seen: 3936 times

Last Updated: Feb 27 '10 at 01:08 AM