码迷,mamicode.com
首页 > Windows程序 > 详细

控制同一窗体的显隐(Toggle和Button)

时间:2016-08-27 15:26:17      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

公共变量的脚本

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class CommonValues : MonoBehaviour 
{
    public GameObject AnswerShowWin;//答案显示窗口
    public Button CloseBtn;

    public GameObject SubmitTog;//提交答案
    void Start () {
    
    }
    
    void Update () {
    
    }
}

Toogle和Button控制同一窗口的显隐

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ToggleControl : MonoBehaviour
{
    private GameObject _SubmitTog;//控制窗口的显隐的Toggle
    private GameObject _AnswerShowWin;//窗口

    public GameObject CommonValuesBG;//挂载公共变量的背景图片

    private Button _CloseBtn;

    bool flag; //获取开关的状态

    bool CloseBtnFlag;//获取窗口的状态

    int _ClickBtnNo;//判断是否点击的参数

    void Awake()
    {
//从CommonValuse脚本获取变量 _SubmitTog
= CommonValuesBG.GetComponent<CommonValues>().SubmitTog; _AnswerShowWin = CommonValuesBG.GetComponent<CommonValues>().AnswerShowWin; _CloseBtn = CommonValuesBG.GetComponent<CommonValues>().CloseBtn;
_AnswerShowWin.SetActive(
false); } void Start() { EventTriggerListener.Get(_SubmitTog).onClick += TogClick; _CloseBtn.onClick.AddListener(delegate { this.CloseBtnClick(); }); } void TogClick(GameObject tog) { flag = _SubmitTog.GetComponent<Toggle>().isOn; _AnswerShowWin.SetActive(flag); } void CloseBtnClick() { CloseBtnFlag = _AnswerShowWin.activeSelf; if (CloseBtnFlag==true) { _AnswerShowWin.SetActive(false); _SubmitTog.GetComponent<Toggle>().isOn = false; flag = false; } } }

 

控制同一窗体的显隐(Toggle和Button)

标签:

原文地址:http://www.cnblogs.com/Cocomo/p/5813009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!