GUI:图形用户界面 1、方法:void OnGUI(){} 2、标签 GUI.Lable(new Rect(left,top,witch,100),str); 3、文本输入域:s

来源:互联网 发布:虎头牌猎枪淘宝网 编辑:程序博客网 时间:2024/04/30 06:18


   第一个场景:
   public class Welcome : MonoBehaviour {
    public float left;
    public float top;
    void OnGUI() {
        GUI.skin.label.fontSize = 30;// 设置字体大小
        GUI.color = Color.yellow;//设置字体颜色
       if( GUI.RepeatButton(new Rect(left,top,100,40),"Welcome")) //点击按钮判断
       {
           GUI.skin.label.fontSize = 10; //字体改变
           Application.LoadLevel(1);  //场景跳转
       }
    }
}

运行结果:

   点击“Welcome”按钮跳转注册场景


  2、注册场景

   public class Register : MonoBehaviour {

    public float left;

    public float top;

    public string user;

    public string password;

    public string age;

    public string manage;

    public Texture2D image;

    void OnGUI()

    {        

        GUI.Label(new Rect(left + 20, top, 200, 20), "欢迎注册");

        GUI.Label(new Rect(left, top + 40, 100, 20), "姓名:");

        user= GUI.TextField(new Rect(left + 40, top + 40, 100, 20), user);

        GUI.Label(new Rect(left, top + 70, 100, 20), "密码:");

        password = GUI.PasswordField(new Rect(left + 40, top + 70, 100, 20), password,"*"[0],10);

        GUI.Label(new Rect(left, top + 100, 100, 20), "年龄:");

        age = GUI.TextField(new Rect(left + 40, top + 100, 100, 20), age);

        GUI.Label(new Rect(left, top + 130, 100, 20), "简介:");

        manage = GUI.TextArea(new Rect(left + 40, top + 130, 150, 60), manage);

        GUI.Label(new Rect(left, top + 200, 80, 20), "头像:");

        GUI.Label(new Rect(left + 40, top + 200, 80, 40), image);

        bool a= GUI.Button(new Rect(new Rect(left, top + 250, 50, 20)), "登录");

        bool b= GUI.Button(new Rect(new Rect(left + 100, top + 250, 50, 20)), "取消");

        if (a == true)

        {

            Application.LoadLevel(0);

        }

        if(b==true)//判断"取消"按钮按下,清空输入内容

        {

            user = "";

            password = "";

            age = "";

            manage = "";

        }

    }

}

运行结果:

    点击登录会跳转,登陆场景


  3、登录场景

    public class Login : MonoBehaviour 

{

    public float left;

    public float top;

    public string user;

    public string password;

    void OnGUI()

    {

        GUI.Label(new Rect(left+30,top,200,20),"欢迎登陆");

        GUI.Label(new Rect(left, top+40, 100, 20), "姓名:");

        user=GUI.TextField(new Rect(left+40, top + 40, 100, 20), user);

        GUI.Label(new Rect(left, top + 70, 100, 20), "密码:");

        password = GUI.PasswordField(new Rect(left + 40, top + 70, 100, 20), password,'*',10);

        bool a=(GUI.Button(new Rect(new Rect(left, top + 100, 50, 20)), "登录"));        

        bool b=GUI.Button(new Rect(new Rect(left + 90, top + 100, 50, 20)), "注册");

        if(b==true)

        {

            Application.LoadLevel(1);

        }

    }

}     

  运行结果:
  

这里有很多U3D资源、U3D培训视频、U3D常见问题、U3D项目源码我们可以一起交流学习


   第一个场景:
   public class Welcome : MonoBehaviour {
    public float left;
    public float top;
    void OnGUI() {
        GUI.skin.label.fontSize = 30;// 设置字体大小
        GUI.color = Color.yellow;//设置字体颜色
       if( GUI.RepeatButton(new Rect(left,top,100,40),"Welcome")) //点击按钮判断
       {
           GUI.skin.label.fontSize = 10; //字体改变
           Application.LoadLevel(1);  //场景跳转
       }
    }
}

运行结果:

   点击“Welcome”按钮跳转注册场景


  2、注册场景

   public class Register : MonoBehaviour {

    public float left;

    public float top;

    public string user;

    public string password;

    public string age;

    public string manage;

    public Texture2D image;

    void OnGUI()

    {        

        GUI.Label(new Rect(left + 20, top, 200, 20), "欢迎注册");

        GUI.Label(new Rect(left, top + 40, 100, 20), "姓名:");

        user= GUI.TextField(new Rect(left + 40, top + 40, 100, 20), user);

        GUI.Label(new Rect(left, top + 70, 100, 20), "密码:");

        password = GUI.PasswordField(new Rect(left + 40, top + 70, 100, 20), password,"*"[0],10);

        GUI.Label(new Rect(left, top + 100, 100, 20), "年龄:");

        age = GUI.TextField(new Rect(left + 40, top + 100, 100, 20), age);

        GUI.Label(new Rect(left, top + 130, 100, 20), "简介:");

        manage = GUI.TextArea(new Rect(left + 40, top + 130, 150, 60), manage);

        GUI.Label(new Rect(left, top + 200, 80, 20), "头像:");

        GUI.Label(new Rect(left + 40, top + 200, 80, 40), image);

        bool a= GUI.Button(new Rect(new Rect(left, top + 250, 50, 20)), "登录");

        bool b= GUI.Button(new Rect(new Rect(left + 100, top + 250, 50, 20)), "取消");

        if (a == true)

        {

            Application.LoadLevel(0);

        }

        if(b==true)//判断"取消"按钮按下,清空输入内容

        {

            user = "";

            password = "";

            age = "";

            manage = "";

        }

    }

}

运行结果:

    点击登录会跳转,登陆场景


  3、登录场景

    public class Login : MonoBehaviour 

{

    public float left;

    public float top;

    public string user;

    public string password;

    void OnGUI()

    {

        GUI.Label(new Rect(left+30,top,200,20),"欢迎登陆");

        GUI.Label(new Rect(left, top+40, 100, 20), "姓名:");

        user=GUI.TextField(new Rect(left+40, top + 40, 100, 20), user);

        GUI.Label(new Rect(left, top + 70, 100, 20), "密码:");

        password = GUI.PasswordField(new Rect(left + 40, top + 70, 100, 20), password,'*',10);

        bool a=(GUI.Button(new Rect(new Rect(left, top + 100, 50, 20)), "登录"));        

        bool b=GUI.Button(new Rect(new Rect(left + 90, top + 100, 50, 20)), "注册");

        if(b==true)

        {

            Application.LoadLevel(1);

        }

    }

}     

  运行结果:
  

这里有很多U3D资源U3D培训视频U3D常见问题U3D项目源码我们可以一起交流学习


0 0
原创粉丝点击