How to activate a sound using a button?

I am creating a zombie type game and it’s going good. But I have this object that I want the player to look at and push F12 to play the music. (kinda like the easter eggs found in Call Of Duty zombie maps). This is what i have so far, but it keeps telling me to insert a semi colan. But there already is one!

var audio01 : AudioClip;
function Update () {
if (Input.GetKeyDown (“f12”))
{
audio.Marilyn Manson - Seizure Of Power(audio01);

}
}

P.S. it tells me to insert it at this line: audio.Marilyn Manson - Seizure Of Power(audio01);

P.S.S. Pictures and videos coming soon. Just really suck at weight painting the models and animating them. :rage:

the problem is that “Marilyn Manson - Seizure Of Power()” is not a function. to solve that problem replace that line with…

audio.clip = audio01;
audio.Play();

oh ok. haha thank you!
but now i have another problem :frowning:
when i save the script and everything i go to drag it on the trigger and it says that i cant put it on the object yet because it has not yet finished or completed the script. or something like that.
Any ideas whats wrong?

whats the exact error

i have a feeling its a problem in another script

I get that problem only when I create a new script and dont open and save it. For some reason the editor has to save it to recognize it.

Ill try. Thank you! If not ill put a picture of what the the thing says.

yeah it didnt work. I even deleted the scripts that had some problems that i didnt need. This is what shows up:

I drag the script onto my object and this pops up:

I click “ok” then click on the bottom to see whats wrong and this pops up:

I click on the red sign and see whats wrong and the part thats wrong is the part thats highlighted:

P.S. Link to bigger pictures (in order)
= http://i1106.photobucket.com/albums/h376/8Wade8/help.png

= http://i1106.photobucket.com/albums/h376/8Wade8/help1.png

= http://i1106.photobucket.com/albums/h376/8Wade8/help2.png

Please help :frowning:

Where is ‘blip2’ defined?

I don’t think any where. I just wanted a radar for my game so you could see where your team is and the zombies. So i searched on unity and found this one. It didn’t work. So I think I’ll just delete that one too.

If it’s not declared/defined anywhere, you’ll get an error. (Look at it this way - how will the compiler know what ‘blip2’ is supposed to refer to otherwise?)

Oh okay, I got you now. But one little problem. I want the play to look at the object and then F12 to play the music. Right now you can look anywhere, even the sky, and push F12 and it will still play the music.

Any suggestions?

It depends on what you mean by ‘look at’, but one option (assuming the object has a collider) would be to use raycasting to determine whether the player is looking more or less directly at the object.

raycasting? I’m sorry for sounding stupid and all but what is that? Is there a script I have to write? Or like a box I have to check mark?

you have to write a script, though i cant help you there, i dont exactly know how to use raycast yet.

Raycasting is done through code. A couple of tips:

  • Search the forums and the documentation for ‘raycast’.
  • Work through some of the various tutorials that are available (this will help you become more familiar with the basics of using Unity and with the basic concepts behind scripting and so forth).

Alright thank you I’ll give it a try. But now there is one other little problem (not with the trigger). The skybox. I go to create one and when i click skybox on the material. All the little squares don’t come up to where you drop your pictures in. Why? How do i fix it?

(Also the one that comes with unity is just all black and still has no squares, as well as the asset terrain package skyboxs)

you have to make the material a skybox. to do this, select you skybox material, click the thing that probably says diffuse of something like that (the little thing that you click thats right underneath the stuff that says the name of the material, but still in the grey box). go down to render fx, and select skybox in the little thing that pops out

Yeah, that’s what I did, and for some reason the squares don’t pop up. It’s just blank showing only the sphere and drop down thing :frowning:

hmm, do you have some errors in your codes at all? (maybe unity is acting funny and is not updating that because of those errors) if not, then there is probably something wrong with either unity (unlikely) or your install of unity (more likely), or even you just need to try again. if it does not work with you trying again, i would uninstall unity, and try reinstalling it.

or you could restart your computer