need a login/password protected scene???
Hi, so i'm new to JS and C# and dont really know much about them, i was wondering if it would be possible to password protect a scene so to speak, like, type in a code, click enter, and it loads a scene. and if the password it wrong, dont load the scene.
it dosent have to be like, connected to a database for accounts or anything like that, i just need the passcode to be like stored in the script. but either way will work fine
Answer by ninjaboynaru · Feb 11, 2016 at 12:58 AM
Yes
This will set the password
PlayerPrefs.SetString("Password", "AVeryUniquePassword");
This will get the password
PlayerPrefs.GetString("Password", "AVeryUniquePassword");
How It Works
PlayerPrefs stores data. Each set of data has a key and a value. You find the data by searching its key.
In this case the key is "Password"
and the data associated with that key is the string "AVeryUniquePassword"
Now all you have to do is have get the input from the user and compare it to the saved password
if(userInput == PlayerPrefs.GetString("Password", "AVeryUniquePassword") )
{
//Code to load scene goes here
}
Warning: This code is untested and probably contains spelling errors