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 Airsofter4692 · Dec 18, 2012 at 09:31 PM · c#erroraudioclick

play sound on click

I am trying to play a sound when a button is clicked but it doesn't work. I have tried both public AudioClip Miss; and public UnityEngine.AudioClip Miss; and latter on I say audio.PlayOneShot(Miss);

I also Selected the audio file and yet when I click in game it says "MissingComponentException There is no AudioSource attached to the GLADIUS game object, but a script is trying to access it. You probably need to add a AudioSource to the game object GLADIUS. Or your script needs to check if the component is attached before using it."

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by liszto · Dec 19, 2012 at 12:07 AM

AS Unity says, you don't have Audiosource in your scene. Without an audiosource, your game cannot read/play a sound peacefully.

To read your audioclip, audio.PlayOneShot( yourAudioclip) can work but you need to do this on your object at start before :

     public AudioClip myclip;
     
     // Use this for initialization
     void Start ()
     {
         this.gameObject.AddComponent<AudioSource>();
         this.GetComponent<AudioSource>().clip = myclip;
         this.GetComponent<AudioSource>().Play();
     }



I invite you to read this documentation about AudioSource and AudioClip

P.S : You need to have an AudioListener in your scene (your camera have one per default)

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 Airsofter4692 · Dec 19, 2012 at 04:14 PM 0
Share

Thanks

avatar image
0

Answer by nubick · Apr 02, 2017 at 08:55 AM

You can use following Unity editor extenstion for buttons click sound management: https://github.com/nubick/unity-button-sounds-editor

Comment
Add comment · Show 3 · 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 eneskoto · Nov 13, 2017 at 10:51 PM 0
Share

Dude thank you so much you have just saved me hours of work with this tool! Thank you sooo much!

avatar image Ethical_Matter · Jun 29, 2018 at 10:51 AM 0
Share

How do I use this..?

avatar image nubick Ethical_Matter · Jun 30, 2018 at 01:32 PM 0
Share

Please read tutorial here: http://nubick.ru/button-sounds-editor-for-unity/

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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

PlayClipAtPoint Qualify with Type Name 2 Answers

OnDestroy() : Some objects were not cleaned up when closing the scene 1 Answer

Playing audio 1 Answer

Help with an error urgent 2 Answers


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