- Home /
Load Scene with password
Hi, i need a way to write the password in Input Field and change scene... Thanks
Answer by StonedLover · Jul 15, 2017 at 08:17 AM
Make a Input field and a button and a Script in the button select onClick a GO which has the script attached then select the onclick Method I wrote also make a Reference to the Inputfield so it can be found f.e. make a "public InputField inputField;" and drag it in the editor;
Here the Script:
void OnLoadButtonClicked()
{
string input = inputField.text;
if (input.Equals("password"))
SceneManager.LoadScene("OtherSceneName");
else
Debug.Log("Wrong Password");
}
Didnt tested it but should work I think
But appear that the InputField dows not existe in the current text, i am begginer in c# :/, can you help me?
yeah of cause u have to import the UI Libary: before class .... using UnityEngine.UI;
then within the class:
private InputField inputField;
` make it public if you want to see it in the Inspector or mark it with that [SerializeField]
then you just have to drag the inputfield into the scripts field
I'm sorry for wasting your time, but I do not speak English and I'm having difficulties translating, could you send me a complete script and how should I do in Unity?
Answer by MaksNeon · Feb 26, 2020 at 07:34 PM
@StonedLover can you send me a completed script too? It realy helps me.),@StonedLover it writes: Unexpected symbol "private" can you help me?
Answer by BrutalQuest · May 12, 2020 at 10:28 AM
Hi @StonedLover and @MaksNeon can you send me the completed script. I have problems with the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class prueba_pass: MonoBehaviour
{
public void PassEnter(string input)
{
string input = inputField.text;
if (input.Equals("benito"))
SceneManager.LoadScene("realidad_aumentada");
else
Debug.Log("Wrong Password");
}
}
Thanks a lot!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to load a scene with playerprefs from a ui element 1 Answer
How do I implement ServicePoint into my feedbackpage 0 Answers
Clear fields after submit 3 Answers