x


Best way to play audio sound effects

Hey guys,

I always wondered what the default way is to playback audio Sound Effects, because my current way seems kinda overly complicated.

Here is how I do it currently:

I have a GameObject, with an AUDIO.js script. I link every AUDIO source from the scene in there like that:

var EnemyHitSound : AudioSource;
static var enemyHit = false;

And I set up the Update function like that:

function Update () {
    if (enemyHit){
       EnemyHitSound.Play();
       enemyHit = false;
    }
}

So when I want to play the Audiofile from any script I just write: AUDIO.enemyHit = true;

This seems like such a hassle and completely counter intuitive. Is there a more straight forward way of being able to play any Audio Source in the scene, from any script?

I really appreciate your help.

Thanks

more ▼

asked Jan 28 '12 at 12:17 PM

drGsus gravatar image

drGsus
11 7 7 10

Look at the Broadcast set of functions in the Reference guide

Jan 28 '12 at 03:36 PM Tasarran
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
var EnemyHitSound : AudioClip;
static var enemyHit = false;

And I set up the Update function like that:
function Update () {
    if (enemyHit) audio.PlayOneShot(EnemyHitSound);

    }
}

whi you don'y use "onCollisionEnter" function?is must fast.check the guide.

more ▼

answered Jan 28 '12 at 01:33 PM

devilkkw gravatar image

devilkkw
297 7 10 18

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

x1031
x527
x224
x64
x55

asked: Jan 28 '12 at 12:17 PM

Seen: 3158 times

Last Updated: Jan 28 '12 at 03:36 PM