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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by carter-carl30 · Apr 22, 2012 at 03:47 PM · unlocklevel selectcomplete

Level select screen unlock on completion of game

Hi, I have made a level select screen for my game. (on my main menu I have "new game" "level select" and "quit".

What I want to do is have it so that the level select is greyed out and once the player completes the game once it unlocks so they can choose any level to play.

How would I go about doing this?

Comment
Add comment · Show 2
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 carter-carl30 · May 17, 2012 at 04:46 PM 0
Share

anyone? help please?

avatar image cregox · May 17, 2012 at 05:00 PM 0
Share

@flamy, that's the answer, not a comment! ;)

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by flamy · May 17, 2012 at 04:55 PM

use playerprefs to save a key at the ending of the game.

and make the level select button enable if the playerpref key is found. so until the game is completed for first time the key wont be saved, hence the level selection wont be unlocked till then.

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 carter-carl30 · May 17, 2012 at 08:04 PM 0
Share

thankyou :D

avatar image carter-carl30 · May 20, 2012 at 01:41 AM 0
Share

@vijayakumar any chance you could give me some pusedo code to get me going? I looked at the player prefs unity script reference but i'm left baffled

avatar image
2
Wiki

Answer by flamy · May 20, 2012 at 02:21 PM

you would have the code for checking last level completion rite in tht place you have to add this code PlayerPrefs.SetInt("gameOver",1);

and in the menu screen you have to check for this value,

  function OnGUI()
     {
     
         if(PlayerPrefs.GetInt("gameOver")==1)
         {
           //here make the button active.  btw you have to use different texture for active and inactive states.
         }
         else
         {
           // draw inactive texture. and also  dont take input (you can notify if u want, infact tht would be better.)
         }
     }


FYI: the PlayerPrefs.GetInt() function will return 0 if key is not found. if this is still not clear just post your menu code, ill edit it for u

Comment
Add comment · Show 5 · 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 carter-carl30 · May 21, 2012 at 06:24 PM 0
Share

Hi vijayakumar, I am using this script for my main menu:

var isQuitButton = false; var mySound : AudioClip; var mySound1 : AudioClip;

function On$$anonymous$$ouseEnter() { //change color of the text renderer.material.color = Color.red; audio.clip = mySound; audio.Play(); }

function On$$anonymous$$ouseExit() { //change the color of the text renderer.material.color = Color.white;

}

function On$$anonymous$$ouseUp() { //are we dealing with a Quit Button? if( isQuitButton ) { //quit the game audio.clip = mySound1; audio.Play(); yield WaitForSeconds (1); Application.Quit();

 }
 else
 {
     //Load level
     audio.clip = mySound1;
     audio.Play();
     yield WaitForSeconds (1);
     Application.LoadLevel(2);
     lives.LIVES = 5;
 }

}

=============

and this one on my level select button:

var mySound : AudioClip; var mySound1: AudioClip;

function On$$anonymous$$ouseEnter() { //change color of the text renderer.material.color = Color.red; audio.clip = mySound; audio.Play(); }

function On$$anonymous$$ouseExit() { //change the color of the text renderer.material.color = Color.white; }

function On$$anonymous$$ouseUp() { //Load level audio.clip = mySound1; audio.Play(); yield WaitForSeconds (1); Application.LoadLevel(55); }

=========== will i need to change my menu to GUI textures?

avatar image flamy · May 22, 2012 at 05:27 AM 0
Share

so level 55 is your level selection screen?

in that case jus enclose everything in the on$$anonymous$$ouseUp() function with the if loop.

 function On$$anonymous$$ouseUp() { 
     if(PlayerPrefs.GetInt("gameOver")==1)
             {
               //Load level audio.clip = mySound1; 
               audio.Play(); yield WaitForSeconds (1); 
               Application.LoadLevel(55); 
             }
             else
             {
               // notify that he has to complete the game once to unlock this.
             }
     }



and no my example was for onGui you don't have to change you code to gui.

but if u want to show inactive texture for button before completion add this below function

 var inActiveTexture:Texture;
 
 function Start()
 {
    
      if(PlayerPrefs.GetInt("gameOver")!=1)
      {
        renderer.material.mainTexture=inActiveTexture;
      }
 
 }



is this clear enough??

avatar image carter-carl30 · May 22, 2012 at 07:03 PM 1
Share

@flamy yes, thank you. Thanks for taking the time to look at my question and help me out :)

I really appriciate all the help from yourself and vijayakumar.

avatar image flamy · May 23, 2012 at 05:30 AM 0
Share

haha np. btw flamy and vijayakumar are both same people ;) it is some problem with unity answers site. vijayakumar is my real name, i have no idea y it shows up

avatar image carter-carl30 · May 23, 2012 at 06:20 PM 0
Share

lol I was wondering! :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

levels unlocking system 3 Answers

Purchase Level Unlock System 1 Answer

Problems with unlocking levels 1 Answer

Redeem / Bonus codes system 1 Answer

Completely Uninstall Unity App on Android device 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