So I was wondering how to make a password using the Unity UI system. So If I type in “password” in input field it brings me to a scene. I can not do this because 1: Im learning C# 2: I have tried many tutorials on this and none of them work. please tell me using c# not Java. Thanks!
If i understand your question correctly, you want to check if the text in the inputfield is equal to password and than open a scene?
1: create a inputfield in the scene
2: create an empty C# script and name it PasswordInputField
3: paste code below in that script
4: attach script on inputfield (or any other gameobject)
5: select the inputfield and in the inspector under “if value change” click the + and drag the gameobject with the script in the field that appears.
6: under function choose passwordinputfield and checkinput (thats the public function in the script)
7: drag the inputfield to the public inputfield field
I wrote this without unity open so maybe i missed a detail in the step by step guide.But it should be something like these steps
code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PasswordInputField : MonoBehaviour {
public InputField inputfield;
public void CheckInput() {
if (inputfield.text == "password") // check inputfield contains the string password
{
Debug.Log("Password accepted"); // just a debug.Log to show that the password is correct (can be removed)
SceneManager.LoadScene("Myscene"); // fill in the name of the scene you want to load
}
}
}
Greetz
Why thanks so much!
baldi!
Bippidy Boppidy,
Your code is now my property
hippity hoppity,
I’m inside your walls.