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 /
This question was closed May 10, 2013 at 07:42 AM by Fattie for the following reason:

Duplicate Question

avatar image
2
Question by MalukoAlegre · May 09, 2013 at 11:50 PM · mousesoundplayenter

How do I play a sound after the mouse goes through an object?

I'm doing a menu for my game and I don't know how to play a sound after the mouse pass through it... I just made it change the color and load the next level. for example.

 using UnityEngine;
 using System.Collections;
 public class play : MonoBehaviour {
     public bool sair = false;
     
     
     
     void OnMouseEnter ()
         {
             renderer.material.color = Color.blue;
         
         }
     void OnMouseExit ()
         {
             renderer.material.color = Color.white;
         }
     void OnMouseDown ()
         {
           if (sair)
         {
             Application.Quit();
         }
         else
         {
             Application.LoadLevel(1);
         }
        }
     }


Comment
Add comment · Show 1
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 Fornoreason1000 · May 09, 2013 at 11:52 PM 0
Share

you mean hover over a button?

3 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by aaronov · May 09, 2013 at 11:57 PM

You need to have an AudioSource attached to your GameObject with an AudioClip assigned to it. Then you simply call Play() on the audio source within the OnMouseEnter() event. You will also need an AudioListener most likely attached to your main camera.

Comment
Add comment · 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
0

Answer by aldonaletto · May 10, 2013 at 12:30 AM

You can simply use audio.Play() to start playing the sound. Add an AudioSource to the menu object and set its Clip field to the desired sound, then add the instruction audio.Play() to the OnMouseEnter event - like this:

     void OnMouseEnter ()
        {
          renderer.material.color = Color.blue;
          audio.Play();
        }


HINT: It's better to uncheck the 3D sound property in the clip (click the audio clip in the Project view to access its properties)

Comment
Add comment · 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
0

Answer by MalukoAlegre · May 10, 2013 at 01:20 AM

hehe...thanks...it worked..! I also put an song to play when the scene is loaded to stay as background music... =D

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

16 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 avatar image avatar image avatar image

Related Questions

How to Have a Random Interval in an Array in between Sounds being Played? 1 Answer

Make footstep script 2 Answers

Can't get my sound to work.. 1 Answer

How to play music and sound / get working radio 0 Answers

make sound work 0 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