x


Sound on collision

I've looked up tons of scirpts for this but none of them really helped or made sence. Just simply trying to make a sound play when you hit an item

the i tried:

function OnTriggerEnter(  otherObject: Collider        ){

    if(otherObject.gameObject.tag == "Player"){
    audio.clip = otherClip;
    audio.Play();
    }
}

It works, but the problem is when i try to put Destroy(gameObject) anywhere in the script it either doesn't destroy but plays sound, or vice versa. What should i do. Thanks :D

more ▼

asked Sep 22 '10 at 04:54 AM

Mattchuu gravatar image

Mattchuu
50 7 10 17

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

1 answer: sort voted first

You can use AudioSource.PlayClipAtPoint()

This will play the sound without it being attached to a specific AudioSource component on a GameObject, so it won't stop playing when the GameObject is destroyed.

more ▼

answered Sep 22 '10 at 08:30 AM

runevision gravatar image

runevision ♦♦
8.1k 29 46 112

(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:

x2499
x525
x72

asked: Sep 22 '10 at 04:54 AM

Seen: 1775 times

Last Updated: Sep 22 '10 at 04:54 AM