控制同一窗体的显隐(Toggle和Button)
Posted CocomoNo1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了控制同一窗体的显隐(Toggle和Button)相关的知识,希望对你有一定的参考价值。
公共变量的脚本
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)的主要内容,如果未能解决你的问题,请参考以下文章