Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by luqazzo · Aug 31, 2015 at 09:27 PM · delay

Delay Application.LoadLevel

Hello! I was trying to make main menu for my game. I wanted to have sound when clicking "start game" button, but when I use yield WaitForSeconds (3); my sound is playing after those 3 seconds, and it plays for only about half a second and then the level loads. I want this sound playing immediately after pressing the button. I was wondering if anybody can help me. Here's my main menu script:

 var isQuit=false;
 var hoverSound : AudioClip;
 var clickSound : AudioClip;
 var levelNumber : int;
 
 function OnMouseEnter(){
   GetComponent.().material.color=Color.red;
   GetComponent.().PlayOneShot(hoverSound);
 }
 
 function OnMouseExit(){
   GetComponent.().material.color=Color.white;
 }
 
 function OnMouseUp(){
 
   if (isQuit==true) {
 
     Application.Quit();
   }
   else{
 
     yield WaitForSeconds (3)
     Application.LoadLevel(levelNumber);
     GetComponent.().PlayOneShot(clickSound);
   }
 }
 
 function Update(){
 
   if (Input.GetKey(KeyCode.Escape)) { 
    Application.Quit();
   }
 }

Sorry for my bad english :D

Comment
Add comment · Show 3
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 Dave-Carlile · Aug 31, 2015 at 09:34 PM 1
Share

Wouldn't you just want to move your call to PlayOneShot before the yield?

avatar image luqazzo · Aug 31, 2015 at 09:39 PM 0
Share

oh, I didnt think about it. I'm so stupid ;( Thank you so much :)

avatar image Dave-Carlile · Aug 31, 2015 at 09:51 PM 0
Share

Learning is never stupid. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by getyour411 · Sep 01, 2015 at 12:31 AM

Personally I would not go the route of artificially pausing the game so a sound can play. Instead, play the sound on an object that has DontDestroyOnLoad so that it transitions into the next scene.

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

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

Related Questions

How to delay a function? 3 Answers

Linux Standalone player slow startup after version 5.2 0 Answers

script delay ("on mouseclick") 0 Answers

Delay while rotating a camera (doesn't happen in the editor) 0 Answers

Hi, Im trying to make a OnTriggerStay2D but with some delay, and I dont know how is, someone can help me please? I share mi code below. 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