I need help solving the error that is in the title.
-
DevLogin.cs(5,35): error CS0103: The name `String’ does not exist in the current context
-
DevLogin.cs(6,35): error CS0103: The name `String’ does not exist in the current context
using UnityEngine;
using System.Collections;public class Devlogin : MonoBehaviour {
private string username = String.Empty;
private string password = String.Empty;
private bool correctLogin;void Update (){ correctLogin = (username == "LegendWill" && password == "admin"); } void OnGUI (){ Rect windowRect; windowRect.x = Screen.width / 2 - 100; windowRect.y = Screen.height / 2 - 50; windowRect.width = 200; windowRect.height = 100; GUI.Window(0, windowRect, OnWindowGUI, "Authentication"); } void OnWindowGUI (){ username = GUILayout.TextField(username); password = GUILayout.PasswordField(password, '*'[0]); if (GUILayout.Button("Login") && correctLogin) { Debug.Log("You logged in!"); enabled = false; } }}
When I change it to a lowercase s, I get even more errors http://prntscr.com/4knr9q
– LegendWillYes, there are further errors in the script (that weren't evaluated before, because of the error at the start): You need to initialise the windowRect: Rect windowRect = new Rect(); OnWindowGUI has to take an argument of type int: void OnWindowGUI(int id) And you can't use indexing with char - use " to make it a string: password = GUILayout.PasswordField(password, "*"[0]);
– AyAMrau@AyAMrau, the real object is String in namespace System(which was what was missing), string is syntactic sugar for String, this goes for int which is really Int32/Int64, but they are in the System namespace and will not show unless your "using" the namespace and of course will cause an error during build.
– Landern