Script for public variables
usingUnityengine;usingSystem.Collections;usingUnityengine.ui; Public classCommonvalues:monobehaviour { PublicGameobject Answershowwin;//Answer display window PublicButton closebtn; PublicGameobject Submittog;//Submit an Answer voidStart () {}voidUpdate () {}}
Toogle and buttons control the display of the same window
usingUnityengine;usingSystem.Collections;usingUnityengine.ui; Public classtogglecontrol:monobehaviour{PrivateGameobject _submittog; //Control the explicit toggle of the window PrivateGameobject _answershowwin; //Window PublicGameobject COMMONVALUESBG;//mount a background image of a public variable PrivateButton _closebtn; BOOLFlag//get the status of the switch BOOLClosebtnflag;//get the state of a window int_clickbtnno;//determine whether the clicked parameter voidAwake () {
//Get variable from commonvaluse script _submittog= commonvaluesbg.getcomponent<commonvalues>(). Submittog; _answershowwin= commonvaluesbg.getcomponent<commonvalues>(). Answershowwin; _CLOSEBTN= commonvaluesbg.getcomponent<commonvalues>(). CLOSEBTN;
_answershowwin.setactive (false); } voidStart () {eventtriggerlistener.get (_submittog). OnClick+=Togclick; _closebtn.onclick.addlistener (Delegate { This. Closebtnclick (); }); } voidTogclick (gameobject tog) {flag= _submittog.getcomponent<toggle>(). IsOn; _answershowwin.setactive (flag); } voidClosebtnclick () {Closebtnflag=_answershowwin.activeself; if(closebtnflag==true) {_answershowwin.setactive (false); _submittog.getcomponent<Toggle> (). IsOn =false; Flag=false; } }}
Controls the display of the same form (toggle and button)