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 adissapong · Feb 03, 2014 at 06:12 AM · guimenu

How can I make the in-game menu remains unchange while changing scenes?

Hi all,

This may be asked already, but I couldn't find the right answer. I'm developing a storybook app using Unity's 2D platform, and it seems to be a platform of choice for me. As I started developing it, I have the main menu done no problem and adding new scenes is fine too. But I got to the part where I want the previous page button, next page button, and options menu (to adjust FX and/or music volume) that I have created for the app in the first scene to remain on every scene. I know that every scene has its own camera, thus I can only create these same buttons and menus on every scene. Is there any other way to create them only one time and reuse them on other scenes?

Thank you!

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
Best Answer

Answer by edcarlo · Feb 03, 2014 at 07:29 AM

You should create a gameobject with a class that holds the values of settings and add "DontDestroyOnLoad(this.gameObject)" inside Awake method.

 public class SettingsValue : MonoBe...{
 
      public float sfxVolume, musicVolume;
 
      void Awake()
      {
           DontDestroyOnLoad(gameObject);
           if (GameObject.FindObjectsOfType(GetType()).Length > 1)
       {
         Destroy(this.gameObject);
       }
      }
 }

You should set the values in your scene where you have the gui menus.

Comment
Add comment · Show 4 · 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 adissapong · Feb 03, 2014 at 07:36 AM 0
Share

Hi edcarlo,

I found this topic "Objects being duplicated with DontDestroyOnLoad". Basically this exactly is my problem. I could now use DontDestroyOnLoad on buttons on my first scene, but they duplicated themselves. So I found this code:

  public void Awake()
         {
         DontDestroyOnLoad(this);
          
         if (FindObjectsOfType(GetType()).Length > 1)
         {
         Destroy(gameObject);
         }
         }

But I don't know where should I put it. A separate script or inside the LoadLevelOnClick? Sorry, I'm new to scripting.

avatar image edcarlo · Feb 03, 2014 at 07:42 AM 0
Share

just add below of DontDestroyOnLoad..

you should put it at the same class

avatar image adissapong · Feb 03, 2014 at 07:47 AM 0
Share

Ok, tried that with the same class and it still got destroyed.

 using UnityEngine;
 
 [AddComponent$$anonymous$$enu("NGUI/Examples/Load Level On Click")]
 public class LoadLevelOnClick : $$anonymous$$onoBehaviour
 {
     public string levelName;
 
     void OnClick ()
     {
         if (!string.IsNullOrEmpty(levelName))
         {
             Application.LoadLevel(levelName);
         }
     }
 
     public void Awake()
     {
         DontDestroyOnLoad(this);
         
         if (FindObjectsOfType(GetType()).Length > 1)
         {
             Destroy(gameObject);
         }
     }
 }
avatar image adissapong · Feb 03, 2014 at 08:27 AM 0
Share

I did this and it works, only that my LoadLevelOnClick script is not working after it does this:

 public void Awake()
     {
         DontDestroyOnLoad(transform.root.gameObject);
         
         if (FindObjectsOfType(GetType()).Length > 1)
         {
             Destroy(transform.root.gameObject);
         }
     }
avatar image
0

Answer by ffxz7ff · Feb 03, 2014 at 06:17 AM

Is this the hourly http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html thread?

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 adissapong · Feb 03, 2014 at 06:58 AM

I tried this by attached the JS script on a button on my first scene. It still got deleted.

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

20 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

Related Questions

When I pause my game and enable canvas and then resume my keyboard starts controlling the menu... 1 Answer

Paused Menu backdrop 1 Answer

menu item and add gadjet 1 Answer

Close my GUI button by repressing the same Hot-key. 3 Answers

Stand alone player 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