加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Unity3d 按钮切换(代码控制)

(2015-05-15 16:59:30)
标签:

unity

分类: Unity3D
按钮可以点击时与不可以点击控制
string[] btnSpriteName = { "cm_btn_grey", "cm_btn_16" };
        Color[] btnValueColor = { new Color(106 / 255.0f, 106 / 255.0f, 106 / 255.0f), new Color(31 / 255.0f, 134 / 255.0f, 0) };
        UILabel uiLabel = mBtn.transform.FindChild("Value").GetComponent();
        UISprite uiSprite = mBtn.GetComponent();
        UIButton uiButton = mBtn.GetComponent();
        BoxCollider boxCollider = mBtn.GetComponent();
        if (isReceived)
        {
            if (!uiButton.isEnabled)
                uiButton.enabled = true;
            if (!boxCollider.enabled)
                boxCollider.enabled = true;
        }
        else
        {
            if (uiButton.isEnabled)
                uiButton.enabled = false;
            if (boxCollider.enabled)
                boxCollider.enabled = false;
        }

        uiSprite.spriteName = btnSpriteName[System.Convert.ToInt32(isReceived)];
        uiLabel.effectColor = btnValueColor[System.Convert.ToInt32(isReceived)];

需要先控制BoxCollider和UIButton,再修改图片,顺序不可乱,否则图片切换不过来

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有