AudioClip Error

Hi Dudes!

I’m getting an Unknown Identifier’sfx1’. Error when i try to play a file called ‘sfx1.mp3’ and I’m too derpy to work out why, I’m guessing it’s because either it can’t find the file in the ‘Resources’ folder or it’s a string and can’t read it? Not sure… :confused:

function Start () {

var myClip:AudioClip;
myClip=sfx1;

audio.PlayOneShot(myClip);
}

Sfx1 is being used like a variable, but it’s never declared or given a value. You’d want something like this:

AudioClip sfx1 = (AudioClip)Resources.Load("sfx1");

Thanks Dameon_

I should set it up Like this right:

function Start () {
AudioClip sfx1 = (AudioClip)Resources.Load("sfx1");
audio.PlayOneShot(sfx1);
}

I’m getting an error saying that it expected a ‘;’ but it seems it’s already there? Any ideas?

Cheers

The error will tell you which line it’s expecting it on. Which one?

Hi there,

The error seems to be on Line 3 which is the following

AudioClip sfx1 = (AudioClip)Resources.Load("sfx1");

Are you doing this in Javascript or C#? Your code block says C#, but in C# your Start method should look more like this:

private void Start() {

Ah I’m a bit of a donkey aint i? Lol! Sorry i meant to say that I’m working with Javascript not c sharp.

Any ideas?

Ta

That’s c# syntax

I think unityscript looks more like this

or

Unityscript actually casts automatically if possible, so you don’t even need to be that explicit, but you might as well, because you can.

Thank you so much you wonderful people!! Really appreciate your help! Now I’ve just gotta work out how to make the audio source play from the cameras position as the scrip is attached to another object, i hope to work that out soon, if not, ill be back :slight_smile: