C# Unity console在按play时不显示调试
我正在创建一个小的登录页面示例,按play键时,如果电子邮件/密码/确认密码不符合设置的条件,我将不会收到预期的任何调试消息 以下是全部代码: 包裹C# Unity console在按play时不显示调试,c#,unity3d,debugging,console.log,C#,Unity3d,Debugging,Console.log,我正在创建一个小的登录页面示例,按play键时,如果电子邮件/密码/确认密码不符合设置的条件,我将不会收到预期的任何调试消息 以下是全部代码: 包裹 using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine; using System; using System.Text.RegularExpressions; 类定义 public class Re
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using System;
using System.Text.RegularExpressions;
类定义
public class Register : MonoBehaviour
{
public GameObject username;
public GameObject email;
public GameObject password;
public GameObject confPassword;
private string Username;
private string Email;
private string Password;
private string ConfPassword;
private string form;
private bool EmailValid = false;
private string[] Characters = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
"A","B","C","D","E","F","G","H","I","J","K","L","M","O","N","P","Q","R","S","T","U","V","W","X","Y","Z",
"1","2","3","4","5","6","7","8","9","0","_","-" };
用户名、电子邮件、密码和确认密码的启动和设置条件
// Start is called before the first frame update
void Start()
{
}
public void RegisterButton()
{
print("Registration Successful");
bool UN = false;
bool EM = false;
bool PW = false;
bool CPW = false;
if (Username != "")
{
if (!System.IO.File.Exists(@"E:/UnityTestFolder/" + Username + ".txt"))
{
UN = true;
}
else
{
Debug.LogWarning("Username Taken");
}
}
else
{
Debug.LogWarning("Username field empty");
}
if (Email != "")
{
EmailValidation();
if (EmailValid)
{
if (Email.Contains("@"))
{
if (Email.Contains("."))
{
EM = true;
}
else
{
Debug.LogWarning("Email is incorrect");
}
}
else
{
Debug.LogWarning("Email is incorrect");
}
}
else
{
Debug.LogWarning("Email is incorrect");
}
}
else
{
Debug.LogWarning("Email field empty ");
}
if (Password != "")
{
if (Password.Length > 5)
{
PW = true;
}
else
{
Debug.LogWarning("Pass must be at least 6 characters long!");
}
}
else
{
Debug.LogWarning("Password field empty");
}
if (ConfPassword != "")
{
if (ConfPassword == Password)
{
CPW = true;
}
else
{
Debug.LogWarning("Passwords do not match!");
}
}
else
{
Debug.LogWarning("Confirm password field empty");
}
if (UN == true &&EM == true &&PW == true &&CPW == true)
{
bool Clear = true;
int i = 1;
foreach (char c in Password)
{
if (Clear)
{
Password = "";
Clear = false;
}
i++;
char Encrypted = (char)(c * i);
Password += Encrypted.ToString();
}
form = (Username + "\n" + Email + "\n" + Password);
System.IO.File.WriteAllText(@"E:/ UnityTestFolder / " + Username + ".txt", form);
username.GetComponent<InputField>().text = "";
email.GetComponent<InputField>().text = "";
password.GetComponent<InputField>().text = "";
confPassword.GetComponent<InputField>().text = "";
print("Registration complete");
}
}
//在第一次帧更新之前调用Start
void Start()
{
}
公共无效注册表按钮()
{
打印(“注册成功”);
bool UN=false;
bool EM=假;
bool PW=假;
bool-CPW=false;
如果(用户名!=“”)
{
如果(!System.IO.File.Exists(@“E:/UnityTestFolder/“+Username+”.txt”))
{
UN=真;
}
其他的
{
Debug.LogWarning(“使用用户名”);
}
}
其他的
{
Debug.LogWarning(“用户名字段为空”);
}
如果(电子邮件!=“”)
{
电子邮件验证();
如果(电子邮件有效)
{
if(Email.Contains(“@”))
{
if(Email.Contains(“.”)
{
EM=真;
}
其他的
{
调试日志警告(“电子邮件不正确”);
}
}
其他的
{
调试日志警告(“电子邮件不正确”);
}
}
其他的
{
调试日志警告(“电子邮件不正确”);
}
}
其他的
{
Debug.LogWarning(“电子邮件字段为空”);
}
如果(密码!=“”)
{
如果(Password.Length>5)
{
PW=真;
}
其他的
{
LogWarning(“Pass必须至少有6个字符长!”);
}
}
其他的
{
Debug.LogWarning(“密码字段为空”);
}
如果(ConfPassword!=“”)
{
if(ConfPassword==密码)
{
CPW=真;
}
其他的
{
LogWarning(“密码不匹配!”);
}
}
其他的
{
Debug.LogWarning(“确认密码字段为空”);
}
如果(UN==true&&EM==true&&PW==true&&CPW==true)
{
bool Clear=true;
int i=1;
foreach(密码中的字符c)
{
如果(清除)
{
密码=”;
清除=错误;
}
i++;
字符加密=(字符)(c*i);
密码+=加密的.ToString();
}
表单=(用户名+“\n”+电子邮件+“\n”+密码);
System.IO.File.writealText(@“E:/UnityTestFolder/“+Username+”.txt),表单);
username.GetComponent().text=“”;
email.GetComponent().text=“”;
password.GetComponent().text=“”;
confPassword.GetComponent().text=“”;
打印(“注册完成”);
}
}
调用更新-按tab按钮在各种占位符之间导航
void Update()
{
if (Input.GetKeyDown(KeyCode.Tab))
{
if (username.GetComponent<InputField>().isFocused)
{
email.GetComponent<InputField>().Select();
}
if (email.GetComponent<InputField>().isFocused)
{
password.GetComponent<InputField>().Select();
}
if (password.GetComponent<InputField>().isFocused)
{
confPassword.GetComponent<InputField>().Select();
}
}
if (Input.GetKeyDown(KeyCode.Return))
{
if (Password != ""&&Email != ""&&Password != ""&&ConfPassword != "")
{
RegisterButton();
}
}
Username = username.GetComponent<InputField>().text;
Email = email.GetComponent<InputField>().text;
Password = password.GetComponent<InputField>().text;
ConfPassword = confPassword.GetComponent<InputField>().text;
}
void EmailValidation()
{
bool SW = false;
bool EW = false;
for (int i = 0; i < Characters.Length; i++)
{
if (Email.StartsWith(Characters[i]))
{
SW = true;
}
}
for (int i = 0; i < Characters.Length; i++)
{
if (Email.EndsWith(Characters[i]))
{
EW = true;
}
}
if (SW = true &&EW == true)
{
EmailValid = true;
}
else
{
EmailValid = false;
}
}
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Tab))
{
if(username.GetComponent().isFocused)
{
email.GetComponent().Select();
}
if(email.GetComponent().isFocused)
{
password.GetComponent().Select();
}
if(password.GetComponent().isFocused)
{
confPassword.GetComponent().Select();
}
}
if(Input.GetKeyDown(KeyCode.Return))
{
如果(密码!=“”&&Email!=“”&&Password!=“”&&ConfPassword!=“”)
{
注册表按钮();
}
}
Username=Username.GetComponent().text;
Email=Email.GetComponent().text;
Password=Password.GetComponent().text;
ConfPassword=ConfPassword.GetComponent().text;
}
无效电子邮件验证()
{
bool-SW=假;
bool-EW=假;
for(int i=0;i
感谢您的帮助。在此处添加[ExecuteInEditMode]属性:
[ExecuteInEditMode]
public class Register : MonoBehaviour
我已经解决了,这是一个愚蠢的错误,我只是在“点击”组件中使用了错误的
GameObject
再次感谢您的帮助。谢谢,但它仍然不起作用。-检查这一页。您在编辑模式下执行脚本时有一些限制。谢谢,我尝试了各种选项,但什么都没有。当我在我的脚本中引入各种类型的错误时,它确实会拾取这些错误,但当我单击Unity上的
Register
时,我条件显示的错误不会出现在控制台中。