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 Flisijn · Mar 15, 2013 at 02:04 PM · cameratriggersoundloadleveldontdestroyonload

Continue playing sound effect on camera after LoadScene

I have a trigger with an OnTriggerEnter script. The script plays a sound effect (Camera.main.audio.PlayOneShot(audioFile);) and loads a new scene. When the new scene is loading the sound is not playing. I don't want to use the trigger as the sound source because the sound is not as clear as it does on the camera. How can I keep continue the sound on the main camera? I also don't want the main camera DontDestroyOnLoad because it is attached to the player.

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

1 Reply

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

Answer by LightSource · Mar 15, 2013 at 02:45 PM

That is quite a few questions. Consider posting multiple questions in the future if they get this long. Regardless, I think I can point you in the right direction.

First, it appears that System.Thread is supported. While your users are in the menu screen, you could have a thread routine run in the background and load all the GameObjects you will be using in the game. (Example below.)

To preserve all your game objects that you have loaded, you will need to call Object.DontDestroyOnLoad(/your object reference/) for each object. Alternatively, you could just add DontDestroyOnLoad(this) to the Awake() function of a MonoBehaviour script that is already attached to the loaded object. Note though that you will need to call Object.Destroy() if you decide to load a new scene and do not need those objects around anymore, otherwise they will persist until the application dies.

However, what about in the case if the user just blows through the menu screen and tries to jump into your game? I think there are two ways to deal with this.

The first way is to just block the user from starting the game by displaying a loading screen (e.g. using a GUITexture) with some sort of animation. Once the thread is finished, you can call Application.LoadLevel("Your Level"); to jump to the next scene. Of course, you still might have some down time while LoadLevel is invoked, so you could just make your loading screen object stick around with DontDestroyOnLoad() and then manually destroy it when the level is ready to go.

The second way is to note how far the thread has gotten, and then kill it. Put the note into some object that gets preserved into the next scene. When the new scene has loaded, continue loading where the previous thread left off. This is more complicated, however it might get your users playing faster if you prioritize the objects such that objects used sooner are loaded before objects that the player will not encounter for several seconds or more. You will need to use some sort of blocking mechanism if the user gets to a point where an object is needed, but it hasn't been loaded yet.

Threading example code: // ... in some MonoBehaviour objectpublic void Start(){ m_thread = new Thread(threadExecute);5. m_thread.Start();} private System.Thread m_thread;private float m_value = 0.0f;10. private void threadExecute(){ // ... normally you would perform object instantiation here. // Instead, lets do something intensive. This takes ~10 seconds 15. // per pass on 2nd gen iPod Touch with OS 3.1.2, Unity iPhone 1.5.1. // int loopCount = 0; while( true ) {20. Debug.Log("threadExecute process start for iteration " + loopCount.ToString()); for( int i = 0; i < 10000000; i++ ) m_value = Mathf.Sqrt((float)(i i i));25. Debug.Log("threadExecute process end for iteration " + loopCount.ToString()); loopCount++; 30. // ... ensure the thread will die if we stop playing in editor. // Otherwise, this thread will keep going until we start a // new debug session. :/ if(! Application.isPlaying ) break;35. } Debug.Log("threadExecute is exiting");}

Original Author:

http://answers.unity3d.com/questions/2021/how-to-speed-up-and-smooth-over-any-load-times-on-iphone-preloading-animated-lo

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

11 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

Related Questions

Losing reference to the camera after loading new scene 0 Answers

how do i trigger a camera and a sound 1 Answer

enter a trigger to access other camera? 1 Answer

Active camera on Start 1 Answer

Play sound only once 2 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