Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by DryreL · Mar 24, 2021 at 04:58 PM · menubuttonssingletonmain menugallery

Trying to make "Gallery Unlocker" script with Singleton

Hello, my game has many scenes and I put these scenes into main menu. However, if player didn't play that scene, player shouldn't enter the scene in main menu gallery section.

This is my Singleton script: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public abstract class Singleton<T> : MonoBehaviour where T : Component
 {
     
     #region Fields
 
     /// <summary>
     /// The instance.
     /// </summary>
     private static T instance;
 
     #endregion
 
     #region Properties
 
     /// <summary>
     /// Gets the instance.
     /// </summary>
     /// <value>The instance.</value>
     public static T Instance
     {
         get
         {
             if ( instance == null )
             {
                 instance = FindObjectOfType<T> ();
                 if ( instance == null )
                 {
                     GameObject obj = new GameObject ();
                     obj.name = typeof ( T ).Name;
                     instance = obj.AddComponent<T> ();
                 }
             }
             return instance;
         }
     }
 
     #endregion
 
     #region Methods
 
     /// <summary>
     /// Use this for initialization.
     /// </summary>
     protected virtual void Awake ()
     {
         if ( instance == null )
         {
             instance = this as T;
             DontDestroyOnLoad ( gameObject );
         }
         else
         {
             Destroy ( gameObject );
         }
     }
 
     #endregion
     
 }

galleryMenuChecker.cs (Singleton in main menu) using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class galleryMenuChecker : Singleton<galleryMenuChecker>
 {
     public bool fromGallery1 = false;
     public bool fromGallery2 = false;
     public bool fromGallery3 = false;
     public bool fromGallery4 = false;
 
     public void DirectScene1()
     {
         if (GameManager.Instance.Scene1AnimationUnlocked == false)
         {
             Debug.Log("You haven't played this scene yet!");
         }
         else if (GameManager.Instance.Scene1AnimationUnlocked == true)
         {
             GameObject.Find("LevelLoader").GetComponent<LevelLoader>().Scene1();
             fromGallery1 = true;
         }
     }
 
     public void DirectScene2()
     {
         if (GameManager.Instance.Scene2AnimationUnlocked == false)
         {
             Debug.Log("You haven't played this scene yet!");
         }
         else if (GameManager.Instance.Scene2AnimationUnlocked == true)
         {
             GameObject.Find("LevelLoader").GetComponent<LevelLoader>().Scene2();
             fromGallery2 = true;
         }
 
     }
 
 
 }
 

And my Game Manager (Singleton). This one has booleans only.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GameManager : Singleton<GameManager>
 {
     // Scene 4 Key is Taken or Not?
     public bool S4_Keycard = false;
 
     // Unity Scene Animations Unlocked or Not?
     public bool Scene1AnimationUnlocked = false;
     public bool Scene2AnimationUnlocked = false;
     public bool Scene3AnimationUnlocked = false;
     public bool Scene4AnimationUnlocked = false;
 }
 

When the player play scene1, I execuete this command in Start(): GameManager.Instance.Scene1AnimationUnlocked = true;

So far so good, everything works fine. Buttons works fine for once. But when I complete the playing of scene1 and return to main menu with ESC pause menu, button no more works.

I checked the situation in edit mode and Singletons works fine, booleans are updated, yet button click does not work.

What did I wrong? Or is there any better way to make a gallery unlocker in Unity? Thank you.

alt text alt text

More images: https://imgur.com/a/xa0jHrE

image-2021-03-24-175157.png (9.7 kB)
image-2021-03-24-175247.png (27.6 kB)
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

Answer by DryreL · Mar 28, 2021 at 05:15 PM

Solution: https://forum.unity.com/threads/singleton-class-inheritance-not-working.446687/

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

157 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 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 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 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 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 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

Application.LoadLevel is missing - Help please! 1 Answer

Why my Gui.button dont are displyed um my scene? 1 Answer

Help needed with menu navigation. 0 Answers

UI buttons not working after 5.6.2 update? 0 Answers

Main menu and game scene overlapping 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