- Home /
Audio clip not playing
Here's my script:
var Open : boolean = false; var GunSound : AudioClip; var GunVolume : float = 0.0; private var ShootAudio : AudioSource;
function Awake(){ ShootAudio = gameObject.AddComponent(AudioSource); ShootAudio.loop = true; ShootAudio.playOnAwake = true; ShootAudio.clip = GunSound; ShootAudio.volume = GunVolume; }
function Update(){ Sound(); }
function Sound(){ if(Open == true && Input.GetKey("space")){ ShootAudio.volume = 1.0; } }
The sound will not play when Open is true, and I hit the space bar.
I tried ShootAudio.Play();
, but that didn't work either.
Thanks ahead for any help.
Answer by Matte Szklarz · Apr 28, 2011 at 04:41 AM
I copied your code exactly into an empty project, attached an .ogg to the script, and attached the script to an empty GameObject. I also checked the box for "open" in the ispector to true.
AND...! It works fine.
Did you check the box in Unity's Inspector? Is it attached to an GameObject? Is there an audio listener checked "on" in the project? There is nothing wrong with the code that I can see.
Ok, after a messing around with it a bit, i discovered the 3d sound settings were messed up. FAIL on my part.. thanks anyways!!
Your answer
Follow this Question
Related Questions
How do I play audio source on Maximize on Play / Audio Source wont play on Maximize 0 Answers
How to control scene lighting based on amplitude of AudioSource? 1 Answer
PlayClipAtPoint Qualify with Type Name 2 Answers
Audio/c#/unity Can i control the duration by time ? 1 Answer
Get audio to just play once 1 Answer