How do I make a level code system?
I'm wanting to make the loading of a level like it used to be in the nes days. this was by entering in a code that the game would give you and it would take you to the level. how would i do this? I have an empty level set up with an input field.
Could not reply your comment, so...
Unity have the "Input Field" (you can create it with the right click in the hierarchy window, under the canvas menu.
To do what you want, just do something like that:
var inputFiled : InputField
var yourString : String
function InputEnd()
{
yourString = inputField.text;
}
In the inputField reference, just drag and drop the InputField that you just created, then call that function by the InputField (it has an section "OnInputEnd" or something like that, just select that script, then). It should pick correctly the string typed by the player.
Answer by fffMalzbier · Jan 19, 2016 at 09:46 AM
In the simplest case, after the user ended his input ( On End Edit event) check in a loop against the code values for the different levels and if the input is matching the level code you can load the corresponding level. From that base you can expand it in the artistic direction you like.
Answer by White8eard · Jan 19, 2016 at 09:55 AM
if(inputcode==levelcode)
{
SceneManager.LoadScene("levelname");
}
predefine the levels based on levelcode..then compare it with input code.
Answer by ForeignGod · Jan 19, 2016 at 09:55 AM
Several ways of doing this, depends on your needs really. This should work to some extent atleast.
if(yourString.Contains("YourLevelCode"))
{
//logic
Application.LoadLevel("x")
}
http://docs.unity3d.com/ScriptReference/String.html http://docs.unity3d.com/ScriptReference/Application.LoadLevel.html
lol, "yourString" should be replaced with the string you are getting from player's input...
oh. Im sorry im such a noob at this kind of stuff i also made a follow up question. http://answers.unity3d.com/questions/1129963/level-code-script-not-working.html i dont know if its correct though :/
Your answer
Follow this Question
Related Questions
Pickup number of objects and have another object appear? 2 Answers
Do we have to open SavedGame every time we do a CommitUpdate when using cloud PlayGames services? 1 Answer
what are some common stratagies for loading assets in unity? 0 Answers
Playerprefs don't work on Android 0 Answers
Setting components variables with another component 0 Answers