首页 > 代码库 > 多个按钮控制多个窗体

多个按钮控制多个窗体

using UnityEngine;using System.Collections;using UnityEngine.UI;public class WinControl : MonoBehaviour {    public GameObject WinBtn1;    public GameObject WinBtn2;    public GameObject WinBtn3;    public GameObject WinBtn4;    public GameObject Win1;    public GameObject Win2;    public GameObject Win3;    public GameObject Win4;    //private GameObject temewin;    // Use this for initialization	void Start ()     {        WinBtn1.GetComponent<Button>().onClick.AddListener(delegate()        {            this.OnClick1(WinBtn1.GetComponent<Button>());        });        WinBtn2.GetComponent<Button>().onClick.AddListener(delegate()        {            this.OnClick1(WinBtn1.GetComponent<Button>());        });        WinBtn3.GetComponent<Button>().onClick.AddListener(delegate()        {            this.OnClick1(WinBtn1.GetComponent<Button>());        });        WinBtn4.GetComponent<Button>().onClick.AddListener(delegate()        {            this.OnClick1(WinBtn1.GetComponent<Button>());        });	}    void OnClick1(Button btn)    {        Win1.SetActive(WinBtn1 == btn);        Win2.SetActive(WinBtn2 == btn);        Win3.SetActive(WinBtn3 == btn);        Win4.SetActive(WinBtn4 == btn);    }}

  

多个按钮控制多个窗体