- Home /
Open scene by typing a word
I know that it's possible to open/change a scene using scripts,like Click on buttons or pressing a keyboard key, or even using the mouse buttons.
But, is it possible to open/change a scene in game by tipping a word? For example "TEST". When player types "TEST" in the keyboard, he is automatically moved to a new scene, like a cheat code. Is this possible? And if it is, what i need to do to make a script that work in this way?
Answer by Firedan1176 · Jul 08, 2016 at 01:45 AM
All you need is an InputField. All you need to do is add a method to when the text is changed, under the TextField component. You'll also want to detect when they press enter, so they can finish typing it before confirming they want to load that level. Then, all you need to do is load the level with the string that is provided.
Edit
In your scene, create an InputField. Add a C# script called LoadLevelCheatCode. In the code, type this:
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class LoadLevelCheatCode : MonoBehaviour {
public string cheatcode = "tilt";
public void SubmitCode(string code) {
if (code.Equals(cheatcode) && SceneManager.GetSceneByName(cheatcode) != null) SceneManager.LoadScene(cheatcode);
}
}
In the script you put on the InputField, fill in the "Cheatcode" field with the level name. It must match case too. Then, on the InputField component, under the "End Edit" field, add one. Drag the C# script you made into the target field. That's it! If you still need help, just leave another comment. You can also personally contact me on Skype: Firedan1176 if you have other questions, or want a more instructive way to do this.
I found and updated a script that i found but i can't get it to work, i think it's because of the Unity 5
Here's the question: http://answers.unity3d.com/questions/1213131/problem-with-cheatcode.html
Are you wanting the cheatcode to be activated as soon as they type in tilt, or do they need to press 'enter' to submit it?