Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 SPOTNINJADUD7890 · Aug 20, 2016 at 09:41 AM · c#leveljava3dtext

I need to be able to have a level selection screen with level locking once you reach a certain level.

Hello! My game need a way to unlock a button in a level after reaching a level so here is an example.

So my game uses a weird way to load stuff. When you complete a level it loads a level complete level. i need a way to make is so that when you reach that level it activates a script in the main menu then will let me click on the level select buttons one level ahead of the level that you completed.

the reason there is no script is because i have no clue at all how to make this happen. an attempt at my level of knowledge would be a waste of time because i can barely code simple scripts and i have no idea where to start such a thing.

javascript would be nice since all of my level loading is done in javascript but c# is also good. if anyone could help me i would greatly appreciate it.

thanks everybody cheers!

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

Answer by BloodBTF · Aug 20, 2016 at 07:42 PM

Try this. Its simple but it might work.

But first, i dont know how you want to check If you actually completed the level. (Do you exit through a door?)

Im just gonna assume were gonna use a trigger collider To check if the level is ended.

First, make 3 custom tags. (You can make as many as you like)

Name them

"Level1"

"Level2"

Etc.

Next create a script, call it levelLoading, then paste this.

(Im using c# btw)

 using UnityEngine;
 using System.Collections;
 
 public class Levels : MonoBehaviour
 {
 static bool level1done = false;
 static bool level2done = false;
 static bool level3done = false;
 
 public GUITexture button1;
 public GUITexture button2;
 public GUITexture button3;
 
 void Start()
 {
 button1.gameObject.SetActive(false);
 button2.gameObject.SetActive(false);
 button3.gameObject.SetActive(false);
 }
 
 void Update ()
 {
 DontDestroyOnLoad(this);
 
 if (level1done)
 {
 Application.LoadLevel("levelSelect");
 button1.gameObject.SetActive(true);
 button2.gameObject.SetActive(true);
 if (button1.HitTest(Input.mousePosition))
 {
 Application.LoadLevel("Level1");
 }
 if (button2.HitTest(Input.mousePosition))
 {
 Application.LoadLevel("Level2");
 }
 }
 
 if (level2done)
 {
 Application.LoadLevel("levelSelect");
 button3.gameObject.SetActive(true);
 if (button3.HitTest(Input.mousePosition))
 {
 Application.LoadLevel("Level3");
 }
 }
 
 if (level3done)
 {
 Application.LoadLevel("levelSelect");
 Debug.Log("you won :D");
 }
 }
 
 void OnTriggerEnter(Collider other)
 {
 if (other.transform.tag == "Level1")
 {
 level1done = true;
 }
 if (other.transform.tag == "Level2")
 {
 level2done = true;
 }
 if (other.transform.tag == "Level3")
 {
 level3done = true;
 }
 }
 }


Also remember to create 3 gui texture objects in your scene and assign them to the script.

Also attach this script to any object in your scene and create 3 box colliders, one for each level, and assign those custom tags to them one by one. (Dont forget to mark them as 'trigger')!

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 SPOTNINJADUD7890 · Sep 02, 2016 at 09:57 PM 0
Share

Well this actually would work i believe. But i have decided on using a different saving system but ty for the help i tried it and it does work so if anyone comes across this there ya go! ty.

avatar image
0

Answer by AYHossGames · Jun 23, 2020 at 07:53 AM

For anyone still looking for other ways of doing this.

 //Put this as a funtion in your "Level Win" funtion.
 nextLevelLoad = (SceneManager.GetActiveScene().buildIndex + 1);
 if (nextLevelLoad>PlayerPrefs.GetInt("levelAt"))
         {
             PlayerPrefs.SetInt("levelAt",nextLevelLoad);
             print(PlayerPrefs.GetInt("levelAt"));
         }

 //Then put this in the start funtion of your Level Select
 private void Start()
     {
         int levelAt = PlayerPrefs.GetInt("levelAt", 2);
 
         for (int i = 0; i < lvlButtons.Length; i++)
         {
             if (i+2>levelAt)  //The plus 2 takes into account that you have 2 scenes before your 
                 {            //first level, a main menu and a level select. Adjust if needed.
                     lvlButtons[i].interactable = false;
                 lvlButtons[i].gameObject.SetActive(false);
             }
         }
     } 


Attach this funtion in the second script to a game object in your level select then put each level in the right place via the inspector.

All props to this youtube vid.

https://www.youtube.com/watch?v=vpbPd6jNEBs

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

how to put the GUI into a gameobject so that when clicked, The GUI pops up, and heres a sample multiple Choice question using GUI, i need the code for it. 1 Answer

How to split up a Text Object into Text Objects of size 1 char at the exact same position? 2 Answers

Web Build Loading Slow 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