- Home /
Question by
mrknt1 · Jan 24, 2017 at 05:20 AM ·
c#unity 5gameobject
how to make a Login Window with unity and c#
hey I am trying to make a login window using a dictionary in c#. I am finding it difficult to find a way to get the gameobjects to work with the code. I have designed the login window in Unity and want to link the username and password field to look through the dictionary and "login" once a pair have been found. anyone able to help me sort this out would be great.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AdminLogin : MonoBehaviour
{
Dictionary<int, string> staffDetails = new Dictionary<int, string>
{
{101,"femi1998" },
{102,"kwaks1999" },
{103,"eman1999" }
};
public void adminDetails()
{
int userName = ...;
string password = ...;
string foundPassword;
if (staffDetails.TryGetValue(userName, out foundPassword) && (foundPassword == password))
{
System.Console.WriteLine("User authenticated");
}
else
{
System.Console.WriteLine("Invalid password");
}
}
}
Comment