Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FutchProductionsSyndicate · Apr 28, 2011 at 04:29 AM · audioaudiosourceaudioclipplay

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FutchProductionsSyndicate · Apr 28, 2011 at 05:05 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges