unity学习(5)——panel

1.unity和vs中都需要主动按ctrl+s,同时在unity中一定要注意退出游戏的执行状态,要不就都白干了。

2.制作注册panel,也是ui的一种而已,再在panel中做一下上一篇的内容。

3.因为这次最后加的image,遮挡住了复制过来的text input 和button,需要调整面板内部ui的上下关系。直接在hierarchy中上下拖动即可,立竿见影。panel和其他的控件之间也存在这种层级关系。

4.为panel挂载如下脚本,这样就可以初始化时隐藏注册panel了。当然用2中的办法也是可以的,后者符合学习过程。

using UnityEngine;
using System.Collections;



public class RegPanelScript : MonoBehaviour {

	//public UILabel accountLabel;
	//public UILabel passwordLabel;
	
	
	void Start () {
        gameObject.SetActive (false);
        //gameObject.SetActive(false);
    }
}

5.点击“注册”按钮打开panel,用的也是SetActive方法。把open方法给登录界面的注册按钮。

using UnityEngine;
using System.Collections;
using System.Security.Cryptography.X509Certificates;



public class RegPanelScript : MonoBehaviour {

	//public UILabel accountLabel;
	//public UILabel passwordLabel;
	
	
	void Start () {
        gameObject.SetActive (false);
        //gameObject.SetActive(false);
    }
    public void Open()
	{
        gameObject.SetActive(true);
    }
}

6.点击按钮关闭panel。用的也是SetActive方法。把close方法给panel界面的取消按钮。

using UnityEngine;
using System.Collections;
using System.Security.Cryptography.X509Certificates;



public class RegPanelScript : MonoBehaviour {

	//public UILabel accountLabel;
	//public UILabel passwordLabel;
	
	
	void Start () {
        gameObject.SetActive (false);
        //gameObject.SetActive(false);
    }
    public void Open()
	{
        gameObject.SetActive(true);
    }
    public void Close()
    {
        gameObject.SetActive(false);
    }
}

7.同理在登陆界面右上角增加一个红色退出按钮

using UnityEngine;
using System.Collections;
using System.Security.Cryptography.X509Certificates;



public class RegPanelScript : MonoBehaviour {

	//public UILabel accountLabel;
	//public UILabel passwordLabel;
	
	
	void Start () {
        gameObject.SetActive (false);
        //gameObject.SetActive(false);
    }
    public void Open()
	{
        gameObject.SetActive(true);
    }
    public void Close()
    {
        gameObject.SetActive(false);
    }
    public void Exit()
    {
        #if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;//在Unity编译器中结束运行
        #else
            Application.Quit();//在可执行程序中结束运行
        #endif
    }
}

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值