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 umrkygsz · Oct 17, 2013 at 01:38 PM · musicawakemain menucontinue

I'm having problem with Continuing Menu Music

Hello everyone, I have a Main Menu music which continues through another scene (like Options) BUT it also continues to my "FirstLevel" which I really don't want it to. I've no idea how to fix this, can somebody help me? Here is the script I'm using:

 private static var instance:MusicContinue;
 
 public static function GetInstance() : MusicContinue
 {
      return instance;
 }
  
 function Awake() {
 
     if (instance != null && instance != this) {
         Destroy(this.gameObject);
         return;
     } else {
         instance = this;
     }
     DontDestroyOnLoad(this.gameObject);
 }
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 meat5000 · Oct 17, 2013 at 01:40 PM

Take this out

  DontDestroyOnLoad(this.gameObject);

Or any DontDestroy you have on your music objects.

Also, consider stopping the music...

[http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.Stop.html][1]

for use with an AudioSource component.

Perhaps try

[http://docs.unity3d.com/Documentation/ScriptReference/Application-loadedLevelName.html][2]

and stop the music when the particular level is loaded. [1]: http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.Stop.html [2]: http://docs.unity3d.com/Documentation/ScriptReference/Application-loadedLevelName.html

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 umrkygsz · Oct 17, 2013 at 02:02 PM 0
Share

Hello, when I took

  DontDestroyOnLoad(this.gameObject);

out, music continuing through my Options scene was gone, it starts it all over again. But the problem was solved as when in FirstLevel, music cut out.

What I only want is to make music stop when I click New Game (which takes players to FirstLevel), but not in Options

Also, couldn't make AudioSource.Stop work. Tried creating an empty object and getting the script in it. I'm not so very good at this, you see :/

Can we use/make something like if(NewGameButton) destroy on load, to not make the music continue only when we get in FirstLevel?

avatar image meat5000 ♦ · Oct 17, 2013 at 02:41 PM 0
Share

Are you playing without an AudioSource Component?

avatar image
0

Answer by ThePositiveMoxie · Oct 17, 2013 at 02:42 PM

AudioSource.Stop() should only be called on the NewGame button statement for when clicked. DontDestroyOnLoad() should be used in the scene you do not want it destroyed.

 var audioSource : AudioSource;
 
     if (ButtonYouArePressingForNewGame){
         audioSource.Stop();
         Application.LoadLevel("NewGameLevel");
     }
     if (ButtonPressedForOptions){
         Application.LoadLevel("OptionsMenu");
     }

In your Options Scene, put in Start or Awake, but DO NOT put it in the NewGame Scene.

 function Awake(){
     DontDestroyOnLoad(ObjectToNotDestroy);
 }

I didn't full test this, but based off the documentation for DontDestroyOnLoad that is how this will work. Easy as that. Hope this is right, as I did no testing.

Comment
Add comment · Show 3 · 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 umrkygsz · Oct 17, 2013 at 05:32 PM 0
Share

Thank you so much for help, but there is one last left (I thought to be very simple one, but I didn't understand your last part so it's probably because of that since it says "AudioSource" destroyed but you're still trying to reach it.)

Anyways, here's my last problem with this (didn't write the last function Awake(){ DontDestroyOnLoad(ObjectToNotDestroy); }

party because I've no idea where to write it to)

When I'm in $$anonymous$$ain$$anonymous$$enu, and get in Options. $$anonymous$$usic continues which is good. When I'm in $$anonymous$$ain$$anonymous$$enu, and get in FirstLevel, $$anonymous$$usic stops which is good

BUT

When I'm in $$anonymous$$ain$$anonymous$$enu, and get in Options, then go back to $$anonymous$$ain$$anonymous$$enu and click New Game should load FirstLevel but nothing happens. And some error in bottom says:

$$anonymous$$issingReferenceException: The object of type 'AudioSource' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. $$anonymous$$ain$$anonymous$$enu.On$$anonymous$$ouseUp () (at Assets/Copycat/Scripts/$$anonymous$$ain$$anonymous$$enu.js:35) UnityEngine.Send$$anonymous$$ouseEvents:DoSend$$anonymous$$ouseEvents(Int32, Int32)

Can someone help?

avatar image umrkygsz · Oct 17, 2013 at 05:38 PM 0
Share

![alt text][2]

alt text

[2]: /storage/temp/16652-mainmenu.png

mainmenu.png (93.8 kB)
options.png (137.2 kB)
avatar image ThePositiveMoxie · Oct 17, 2013 at 05:42 PM 0
Share

Easy fix... include the same DontDestroyOnLoad in Awake in your main menu as well. So it carries over between options, then back. Not including it in the main menu will destroy the one that's in options. So it no longer exists. That is why you get the error.

This needs to be included in any kind of script you want. As long as you place it in start or awake functions and are calling to the right AudioSource's object.

Also you won't be able to goto $$anonymous$$ain$$anonymous$$enu only because of the error. Script won't run through completely because it found an error, object destroyed. So it doesn't know what to do. Once that's fixed you will be able to freely go into New Game again.

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

16 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

Related Questions

Stop continuing music (Please Help) 1 Answer

Music continued in the all level 1 Answer

Muting all Sound / Music from options menu 1 Answer

PlayerPrefs Resets Automatically upon returning to the Main Menu 2 Answers

How to have music not restart between scenes? 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