• 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 ethanol3310 · Apr 28, 2020 at 01:46 PM · buttonscene-loadingindex

Why won't the scene unlock?

So when the ball hits the platform, I want the unlockLevel int to equal the scene build index.

Here is my script that defines the int

using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; using UnityEngine;

public class ChangeScenes : MonoBehaviour { [SerializeField] private string newLevel;

 public static int unlockLevel = 0;
 public int SceneLoad;


 

 // Start is called before the first frame update
 void Start()
 {
     SceneLoad = SceneManager.GetActiveScene().buildIndex;
     Debug.Log(SceneLoad.ToString());
 }

 // Update is called once per frame
 void Update()
 {


 }
 void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.tag == "Goal") { 
     SceneManager.LoadScene(newLevel);
         

        
     
 }

     if(SceneLoad == 4)
     {

         unlockLevel = 4;
         Debug.Log("Next Level Unlocked");

     }

     if (SceneLoad == 5)
     {

         unlockLevel = 5;

     }

     if (SceneLoad == 6)
     {

         unlockLevel = 6;

     }
     if (SceneLoad == 7)
     {

         unlockLevel = 7;

     }


     if (SceneLoad == 8)
     {

         unlockLevel = 8;

     }
     if (SceneLoad == 9)
     {

         unlockLevel = 9;

     }

     if (SceneLoad == 10)
     {

         unlockLevel = 10;

     }
     if (SceneLoad == 11)
     {

         unlockLevel = 11;

     }

     if (SceneLoad == 12)
     {

         unlockLevel = 12;

     }
     if (SceneLoad == 13)
     {

         unlockLevel = 13;

     }
     if (SceneLoad == 14)
     {

         unlockLevel = 14;

     }

     if (SceneLoad == 15)
     {

         unlockLevel = 15;

     }
     if (SceneLoad == 16)
     {

         unlockLevel = 16;

     }

     if (SceneLoad == 17)
     {

         unlockLevel = 17;

     }




 }

}

Here is my script that unlocks the level

using System.Collections; using System.Collections.Generic; using UnityEditor.iOS; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;

public class UnlockAll : MonoBehaviour { public Button button1; public Button button2; public Button button3; public Button button4; public Button button5; public Button button6; public Button button7; public Button button8; public Button button9; public Button button10; public Button button11; public InputField input; public Text text; public Button button12; public Button button13; public string answer; public ChangeScenes script; public InputField winText; public string win = "Demo Reached, More Levels Coming Soon!"; public Button[] levelButtons; public int sceneIndex;

 void Start()
 {
     sceneIndex = SceneManager.GetActiveScene().buildIndex;
     Debug.Log(sceneIndex);



 }
 void Update()
 {
     answer = input.text;

     if ( answer == "UnlockAll" && Input.touchCount>0 || Input.GetKeyDown(KeyCode.Return))
     {

         button1.interactable = true;
         button2.interactable = true;
         button3.interactable = true;
         button4.interactable = true;
         button5.interactable = true;
         button6.interactable = true;
         button7.interactable = true;
         button8.interactable = true;
         button9.interactable = true;
         button10.interactable = true;
         button11.interactable = true;
         button12.interactable = true;
         button13.interactable = true;
         Debug.Log("Levels Enabled");


     }
     





     if (ChangeScenes.unlockLevel == 4)
     {

         button1.interactable = true;
         Debug.Log("It Works");

     }









 }

}

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
1

Answer by Luis_Gan · Apr 28, 2020 at 07:01 PM

There is many issues... Where is SceneManager.LoadScene(newLevel); "newLevel" coming from? Why instead of if(SceneLoad == 4) { unlockLevel = 4; } just unlockLevel = SceneManager.GetActiveScene().buildIndex; and why did you change the scene before set those variables? The same happens with this button1.interactable = true; just use a loop.

     public InputField input;
     public Button[] buttons;
     string answer;
     void Update()
     {
         answer = input.text;
 
         if (answer == "UnlockAll" && Input.touchCount > 0 || Input.GetKeyDown(KeyCode.Return))
         {
             foreach (var item in buttons)
             {
                 item.interactable = true;
             }
 
             Debug.Log("Levels Enabled");
         }
 
         buttons[ChangeScenes.unlockLevel - 1].interactable = true;      
     }
Comment
Add comment · Show 1 · 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 ethanol3310 · Apr 29, 2020 at 04:24 AM 0
Share

@$$anonymous$$ It works when I transition from my level to the level selection but not after I transition from level selection to another scene then back to level selection. Any suggestions and thanks for the help

avatar image
0

Answer by ethanol3310 · Apr 30, 2020 at 05:12 AM

Can anyone else solve my problem. My new scripts are

the one that unlocks the level using System.Collections; using System.Collections.Generic; using UnityEditor.iOS; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;

public class UnlockAll : MonoBehaviour { public Button[] buttons; public InputField input; public Text text;
public string answer; public ChangeScenes script; public InputField winText; public string win = "Demo Reached, More Levels Coming Soon!"; void Start() {

 }
 void Update()
 {

     buttons[ChangeScenes.unlockLevel - 3].interactable = true;
     answer = input.text;

     if ( answer == "UnlockAll" && Input.touchCount>0 || Input.GetKeyDown(KeyCode.Return))
     {

         
         Debug.Log("Levels Enabled");
     }
     





   









 }

and the one that changes scenes

using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; using UnityEngine;

public class ChangeScenes : MonoBehaviour { [SerializeField] private string newLevel;

 public static int unlockLevel = 0;
 public int SceneLoad;


 

 // Start is called before the first frame update
 void Start()
 {
     SceneLoad = SceneManager.GetActiveScene().buildIndex;
     Debug.Log(SceneLoad.ToString());
     
 }

 // Update is called once per frame
 void Update()
 {

     unlockLevel = SceneLoad;

     
 }
 void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.tag == "Goal") {

         
         SceneManager.LoadScene(newLevel);

        
        
     
 }

    




 }

}

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

buttons not being able to be clicked? 1 Answer

Why does using Buttons slow down scene loading? 0 Answers

Using UI.Button to Load Another Scene? (using outdated tutorial video) 1 Answer

Adding a texture to array textures?! 1 Answer

Any way to detect if a button is held down when the scene loads? 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