Simple Audio Problem?

Updated on February 24, 2016 in [A] Audio
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on January 5, 2016

Hey guys!

So I’m almost done making my first game but I left all the audio to do last and, well, now I’m stuck. I know its an easy fix I’m just having trouble figuring it out.

Basically I have the following piece of script for my cash register opening/closing script:

function changeRegisterState ()
{
if (registerIsClosed)
{
theRegister.animation.CrossFade(“RegisterOpen”);
theRegister.audio.PlayOneShot(“CashRegisterOpen”);
registerIsClosed = false;
}
else
{
theRegister.animation.CrossFade(“RegisterClose”);
theRegister.audio.PlayOneShot(“CashRegisterClose”);
registerIsClosed = true;
}
}

Everything works fine I just don’t know what to attach the audio source to, or how to get it to hold the 2 audio files (one for opening one for closing).

Please help. Thanks!

  • Liked by
Reply
2 on January 5, 2016

At the top of your script, I would add (looks like you’re using javascript) :

var cashRegisterOpen : AudioClip;
var cashRegisterClose : AudioClip;

then you can drag your audio files to this script sitting on your register in the scene. add a new audio source component to the cash register object, and if you like, you could make the audio source 2D so that the sound effect is sent straight to the output. If it’s 3D, then the volume will be dependent on how close the player (more specifically, the audio listener) is from the register.

Let me know if this works, or if you try something else.

on February 24, 2016

So Sorry for the late response. This worked great thank you so much!

Devoted
on February 24, 2016

I’m glad it helped!

Show more replies
  • Liked by
Reply
Cancel