- Home /
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?
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.
@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
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
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?
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??
@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.
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
Your answer
Follow this Question
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