不管玩单机还是网游,都有个登陆界面,用玩家的账号信息来识别身份。
unity里可以使用GUI来制作登陆页面,随便选择一个场景,然后给主摄像头添加一个脚本,脚本内容如下
using UnityEngine;
using System.Collections;
public class GUI_login : MonoBehaviour {
private string user_name;
private string user_pwd;
private bool isShowWindow;
private Rect windowRect;
// Use this for initialization
void Start () {
//对用户名和密码进行初始化
user_name = "";
user_pwd = "";
isShowWindow = false;
windowRect = new Rect(10,100,100,50);
}
void OnGUI()
{
GUILayout.BeginHorizontal();//开始水平布局,默认是垂直的
GUILayout.Label("用户名:", GUILayout.Width(70));
user_name = GUILayout.TextField(user_name, GUILayout.Width(100));//获取屏幕上输入的内容,保存到变量中
GUILayout.EndHorizontal();//布局结束