我正在尝试在Unity中的Javascript中创建一个简单的登录GUI。我目前从下面的代码中获得了一个简单的GUI,但我已经尝试了一段时间来做一些额外的事情:
感谢您的帮助:D
#pragma strict
var newSkin : GUISkin;
var logoTexture : Texture2D;
var aTexture : Texture;
private var username : String = ""; // String content would be shown as placeholder text
private var password : String = ""; // String content would be shown as placeholder text
private var submitted : boolean = false;
private var windowRect0 : Rect;
function Start()
{
}
function OnGUI() // Load GUI skin GUI.skin = newSkin;
{
var screenWidth = Screen.width;
var screenHeight = Screen.height;
var windowWidth = 300;
var windowHeight = 180;
var windowX = ( 50 );
var windowY = ( 50 );
GUI.Box(Rect(0, 0, Screen.width, Screen.height), "" ); // Box around the menu to display the background image
// Postion the login window
windowRect0 = Rect( windowX, windowY, windowWidth, windowHeight );
// Display the login window for the user form below
GUILayout.Window( 0, windowRect0, UserForm, "" );
}
function UserForm()
{
GUILayout.BeginVertical();
// Username Field
GUILayout.BeginHorizontal();
GUILayout.Label("Username ", GUILayout.Width(80));
username = GUILayout.TextField( username );
GUILayout.EndHorizontal();
// Password Field
GUILayout.BeginHorizontal();
GUILayout.Label("Password ", GUILayout.Width(80));
password = GUILayout.TextField( password );
GUILayout.EndHorizontal();
if ( GUILayout.Button( "Login" ) ) // Login button
{
submitted = true;
}
if ( GUILayout.Button( "Reset Password" ) ) // Reset password
{
username = "Username ";
password = "Password ";
submitted = false;
}
if ( GUILayout.Button( "Support" ) ) // Support button
{
// Enter action here when the "Support" button is pressed
}
if ( submitted )
{
GUILayout.Label("Submitted!");
}
GUILayout.EndVertical();
}
答案 0 :(得分:0)
前一段时间我正在开展一个类似的项目,我使用了GUI.passwordfield (https://docs.unity3d.com/Documentation/ScriptReference/GUI.PasswordField.html) 这会将输入设置为星号。 我真的不知道你对第二个问题的意思,但第三个问题: 您可以轻松地为布局信息分配布局信息,如下例所示:
}
if (GUI.Button(Rect(10,70,50,30),"Click"))
Debug.Log("Clicked the button with text");
}
重要的是这个位(10,70,50,30)这意味着按钮是左边10px,顶部70px,50px,宽和30px高。 您几乎可以在每个元素上使用它。
请参阅http://docs.unity3d.com/Documentation/ScriptReference/index.html了解详情。