Version: 2020.1

GUILayout.PasswordField

切换到手册
public static string PasswordField (string password, char maskChar, params GUILayoutOption[] options);
public static string PasswordField (string password, char maskChar, int maxLength, params GUILayoutOption[] options);
public static string PasswordField (string password, char maskChar, GUIStyle style, params GUILayoutOption[] options);
public static string PasswordField (string password, char maskChar, int maxLength, GUIStyle style, params GUILayoutOption[] options);

参数

password 要编辑的密码。应将该函数的返回值指定给该字符串,如示例中所示。
maskChar 用于掩盖密码的字符。
maxLength 字符串的最大长度。如果省略,用户可以键入任意长度的字符串。
style 要使用的样式。如果省略,则使用当前 GUISkintextField 样式。

返回

string 编辑后的密码。

描述

创建一个可让用户输入密码的文本字段。

\ 游戏视图中的密码字段。

using UnityEngine;

public class ExampleScript : MonoBehaviour { string passwordToEdit = "My Password";

void OnGUI() { // Make a password field that modifies passwordToEdit. passwordToEdit = GUILayout.PasswordField(passwordToEdit, "*"[0], 25); } }