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 Tobis123 · Jan 01, 2015 at 08:25 PM · gameobjectbuttonsound

When mouse on button needs to play sound

Hello guys.

I got:

1)Gameobject - _Music2

2)JS file - Music2

3)Music file - music2

My JS file code:

 var sound : AudioClip ;
  
  function MouseOnEnter () {
          audio.PlayOneShot(music2);
  }

I add my JS script to my gameobject (_Music2) And i add my music file to my gameobject. alt text

I add gameobject (_Music2) to my button. Because i want when mouse go on button, it make sound.. alt text

I add my music file (music2) to my JS file (Music2) I start my scene, but sound doesnt play.. why?

untitled.png (12.1 kB)
untitled.png (12.2 kB)
Comment
Add comment · Show 4
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 Namey5 · Jan 01, 2015 at 09:11 PM 0
Share

Have you tried either: using an audio source, or using a GUI.Button ins$$anonymous$$d?

avatar image Tobis123 · Jan 01, 2015 at 10:06 PM 0
Share

I have try to use audio source, i have add audio source to my gameobject. And in on click() i have press Audio source Play (). I will try with GUI.Buttons.

avatar image Tobis123 · Jan 02, 2015 at 12:03 PM 0
Share

Gui button is UI button, right? I have ui buttons...

avatar image Tobis123 · Jan 02, 2015 at 12:14 PM 0
Share

Sorry, got fail... Gui button isnt ui button... i dont like gui buttons, dont wanna try with that.. i like ui buttons..

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Thom Denick · Jan 02, 2015 at 12:51 AM

If there are no errors, this is likely because your audioclip is not set to 2D, and the clip is playing too far from your AudioListener.

Comment
Add comment · Show 12 · 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 Tobis123 · Jan 02, 2015 at 09:48 AM 0
Share

$$anonymous$$y audioclip is set to 2D. What i need to do, to get clip closer to AudioListener? I can try to drag my gameobject closer to my main camera, where is audio listener. Or i need drag my button, what i want to make sound, to closer to main camera?

avatar image Tobis123 · Jan 02, 2015 at 12:02 PM 0
Share

Have try my gameobject drag closer to my main camera where is audio listener, but sound doesnt play...

avatar image Tobis123 · Jan 02, 2015 at 12:39 PM 0
Share

$$anonymous$$yb someone can write step by step what need to do? Than i will check if i have all steps do..

avatar image Tobis123 · Jan 02, 2015 at 01:47 PM 0
Share

It seems that cant add sound to UI buttons ;/

avatar image Thom Denick · Jan 02, 2015 at 04:52 PM 0
Share

If it's set to 2D, I was wrong. Your code is fine, so it must be something else wrong. Does the clip preview fine in Unity Editor? What happens when you put on an AudioSource attached to the same GameObject as the AudioListener with "AutoPlay" checked on?

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Problem with texture to reset and re-enter the same texture 0 Answers

Background music and button sound at the same time PROBLEM 1 Answer

Destroy a Gameobject with a UI Button 3 Answers

Unity ads , can't we show video by clicking a button? 1 Answer

Create clickable GameObjects (JS) 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