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 imboxmisty · Jan 30, 2014 at 05:21 PM ·

Problems when i click the button it has no sound in unity 3d c# help me guys this is for my thesis project

using UnityEngine; using System.Collections;

public class MainMenu : MonoBehaviour {

 private delegate void MenuDelegate();
 
 public AudioClip click;
 private float screenHeight;
 private float screenWidth;
 private float buttonHeight;
 private float buttonWidth;
 //Variables End
 void Start ()
 {
     screenHeight = Screen.height;
     screenWidth = Screen.width;
     
     buttonHeight = screenHeight * 0.1f;
     buttonWidth = screenWidth * 0.5f;
     
     //here we set the menuFunction to point to the anyKey function, which is further down in the code
 
 }

 void OnGUI () {
             // Make a background box
             //GUI.Box (new Rect (Screen.width / 2 - 190, 100, 100, 100), "Menu");
     
             // Make the first button. If it is pressed, Application.Loadlevel (Beta World) will be executed
             GUI.backgroundColor = Color.green;
     if(GUI.Button(new Rect((screenWidth - buttonWidth) * 0.5f, screenHeight * 0.4f, buttonWidth, buttonHeight), "Choose Mode"))
         
     {
                     Application.LoadLevel ("gamemode");
                     audio.PlayOneShot (click);
         
             }
     
             // Make the second button.
             GUI.backgroundColor = Color.yellow;
     if(GUI.Button(new Rect((screenWidth - buttonWidth) * 0.5f, screenHeight * 0.5f, buttonWidth, buttonHeight), "Instruction"))
         
     {
                     Application.LoadLevel ("instruction");
                     audio.PlayOneShot (click);
             }
     
             //Exit Game button
     GUI.backgroundColor = Color.blue;
     if(GUI.Button(new Rect((screenWidth - buttonWidth) * 0.5f, screenHeight * 0.6f, buttonWidth, buttonHeight), "Option"))
         
     {

                     Application.LoadLevel ("option");
                     audio.PlayOneShot (click);
             }
     
             //Options button, Use variables
             GUI.backgroundColor = Color.red;
     if(GUI.Button(new Rect((screenWidth - buttonWidth) * 0.5f, screenHeight * 0.7f, buttonWidth, buttonHeight), "Top Score"))

     {
                     Application.LoadLevel ("score");
                     audio.PlayOneShot (click);
             }
     }

 }
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 raptorkwok · Oct 27, 2014 at 04:16 AM

You should play audio first, then load level. Reverse the sequence.

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 Riwels · Oct 27, 2014 at 05:11 AM

As @raptorkwok said, you must play the audio first.

You will need to wait for the end of the sound or play it from a persistent object. if you don't, it will stop playing the sound as soon as the new scene is loaded.

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

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

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

Related Questions

Unity fit for sandbox MMO? 1 Answer

Procedureal scripting in unity 1 Answer

Data Visualization 1 Answer

Detect if a mousewheel is scrolling and what direction it is scrolling 2 Answers

Can we have point light shadows for mobile devices in Unity? 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