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 bansalgirish8 · Apr 11, 2014 at 12:07 PM · audioapplication.loadlevel

I am trying to play sound clip immidiately before loading new scene

I am trying to play sound clip immidiately before loading new scene.My sound clip does't fully get played before i switch to new scene.what should i do??

i can't use do not destroy on load.

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 Owen-Reynolds · Apr 11, 2014 at 02:12 PM 0
Share

Why can't you use dontDestroyOnLoad? Did you lose a bet?

Isn't the primary point of the music to play over the loading screen? Not just adding an extra delay to the game, then having the same silent, boring load screen as before?

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by bansalgirish8 · Apr 18, 2014 at 10:52 AM

Thanks everyone for your help. You helped me to track down the problem. Actually i was looking for rigidbody.constraints=RigidbodyConstraints.FreezeAll; I actually needed a replacement for Time.TimeScale=0. this is what i did:

 using UnityEngine;
 using System.Collections;
 IEnumerator OnTriggerEnter( Collider _other )
     {
            if (_other.CompareTag ("w")) {
             //Time.timeScale=0;
             this.rigidbody.constraints=RigidbodyConstraints.FreezeAll;
             _other.rigidbody.constraints=RigidbodyConstraints.FreezeAll;
             this.GetComponent< AudioSource>().priority=0;
             audio.PlayOneShot(wall);
             time = Time.timeSinceLevelLoad;
             
             yield return new WaitForSeconds(0.3f);
             
             Application.LoadLevel("GameOver");
 }
 }


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
2

Answer by GeorgesAbitbol · Apr 11, 2014 at 01:14 PM

Start playing the sound, and regularly check "yourAudioSource.isPlaying" to know when the sound has finished playing, then load the next scene.

EDIT: You could also check the AudioClip's length, start playing the sound, wait enough time, then load 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
avatar image
2

Answer by HarshadK · Apr 11, 2014 at 01:37 PM

You can load your level using a co-routine where in you put the co-routine to execute after the time duration of your audio clip.

Check this Psuedo-code in c#:

In OnTriggerEnter():

 if(player dies){
     play audio;
     StartCoroutine("LoadNewLevel");
 }

In your Co-routine:

 IEnumerator LoadNewLevel() {
     yield return new WaitForSeconds(TheTimeOfYourAudioClip);
     Application.LoadLevel("YourLevel");
 }

Let us know the outcome.

Comment
Add comment · Show 2 · 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 bansalgirish8 · Apr 12, 2014 at 04:58 AM 0
Share

Thanks it helped to play whole sound clip but i can no longer stop the time scale. If i don't set time scale to 0 my player passes the enemies and if i use it the coroutine doesn't run this is what i did:

IEnumerator LoadNewLevel() { yield return new WaitForSeconds(2); Application.LoadLevel("GameOverNgui"); }

IEnumerator OnTriggerEnter( Collider _other ) { if (_other.CompareTag ("Skull")) {

this.GetComponent< AudioSource>().priority=0; audio.PlayOneShot(wall);
Time.timeScale=0; StartCoroutine("LoadNewLevel"); } }

avatar image saud_ahmed020 · Mar 12, 2015 at 02:45 PM 0
Share

I think co-routine approach towards this problem is not 100% correct.

Reason: If you have more than one buttons e.g b1 and b2, and you want to load scene by pressing b1. After pressing b1 your co-routine will start and at the same time you press b2 then what happen?

For this problem, I will recommend make a singleton class and attach general audio source and audio listener, and call DontDestroyOnLoad(audiolistener) method in this singleton class awake method and reside this singleton class where you need audio listener and audioSource.

if(player dies){ play audio; StartCoroutine("LoadNewLevel"); }

IEnumerator LoadNewLevel() { while(audiosource.isPlaying) { yield return null; }
Application.LoadLevel("YourLevel"); }

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

27 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

Related Questions

problems with continuous audio between scenes 1 Answer

5.1 Channels is backwards in unity (non 3D) 0 Answers

Application.LoadLevel(); not working 2 Answers

Downloading Audio Durin RunTime.. 1 Answer

Audio sounds on gameobject 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