Search Unity

Unity UI How do I make a password?

Discussion in 'UGUI & TextMesh Pro' started by Deleted User, Aug 4, 2018.

  1. Deleted User

    Deleted User

    Guest

    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!
     
  2. JeffreyA

    JeffreyA

    Joined:
    Jun 6, 2017
    Posts:
    17
    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:
    Code (CSharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.UI;
    7. using UnityEngine.SceneManagement;
    8. public class PasswordInputField : MonoBehaviour {
    9.  
    10.     public InputField inputfield;  
    11.  
    12.     public void CheckInput() {
    13.         if (inputfield.text == "password")      // check inputfield contains the string password
    14.         {
    15.             Debug.Log("Password accepted");     // just a debug.Log to show that the password is correct (can be removed)
    16.             SceneManager.LoadScene("Myscene");  // fill in the name of the scene you want to load
    17.         }
    18.     }
    19. }
    20.  
    21.  
    22.  
    Greetz
     
    Last edited: Aug 5, 2018
  3. Deleted User

    Deleted User

    Guest

    Why thanks so much!
     
  4. ajthompson077

    ajthompson077

    Joined:
    Jul 30, 2022
    Posts:
    1
  5. Deleted User

    Deleted User

    Guest

    Bippidy Boppidy,
    Your code is now my property
     
  6. NearRaindrop116

    NearRaindrop116

    Joined:
    May 26, 2023
    Posts:
    4
    hippity hoppity,
    I'm inside your walls.