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
1
Question by SmileFace100 1 · Mar 30, 2011 at 02:53 PM · scenemusic

Destroy "Don'tDestroyOnLoad" script in a specific scene ??

I want to Destroy "Don'tDestroyOnLoad" script in some scenes and recall it on the next scene

Hope i can clear what i want..

for an example: I attached "Don'tDestroyOnLoad" script to empty gameObject that's hold some music .. I want the music to continue playing until the player reach specific scene and then stop the script or destroy it and when i pass the scene i want to recall the music back.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Justin Warner · Mar 30, 2011 at 03:02 PM

http://answers.unity3d.com/questions/2237/easy-question-how-to-disable-script-object

Might help you out... Was thinking when I read the title why you'd use that function... But music does make sense, haha. Hope this helps a little though.

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 Tommy · Mar 30, 2011 at 03:05 PM

Maybe you can deactivate the script then activate it again? Here's some code for that:

GetComponent(scriptName).enabled = false;

Then to activate it again use:

GetComponent(scriptName).enabled = true;

To check what scene you'r in use:

if (Application.loadedLevel == "1")
{
 //change script here.
}

It will end up something like this:

if (Application.loadedLevel == "1") { GetComponent(soundScriptName).enabled = true; }

else if (Application.loadedLevel == "2") { GetComponent(soundScriptName).enabled = false; }

else if (Application.loadedLevel == "3") { GetComponent(soundScriptName).enabled = true; }

This will make the sound play in scene one, stop playing in scene two, then begin playing in scene 3 again. (Hopefully...)

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 Nicolaj Schweitz · Mar 30, 2011 at 07:40 PM

There is no need to Destroy the gameObject with the AudioSource and the DontDestroyOnLoad script.

It sounds to me like you simply should call audio.Stop(), audio.Pause(), or audio.mute = true on the gameObject with the AudioSource.

If you feel daring, you could play around with audio.volume and Mathf.Lerp to create a little fading function that is triggered on the AudioSource over time.

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

No one has followed this question yet.

Related Questions

How to have music not restart between scenes? 1 Answer

Accessing non-static functions in an unattached, non-scene, "project" script 1 Answer

Playing Music After Seconds Works, But When Scene Reloads, Script Doesn't Work 1 Answer

Setting variable as type "Scene" 4 Answers

Timer gets executed in the wrong scene 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