- Home /
GUILayer.enabled = false being ignored
I seem to be facing an error whereby I can't disable my GUI Layer.
I'm disabling the guilayer then taking a screenshot and then re-enabling it - but this doesn't seem to be working.
private GUILayer guiLayer;
// Use this for initialization
void Start () {
guiLayer = GameObject.Find("MainCamera").GetComponent<GUILayer>();
}
public void CaptureButton(){
if(GUI.Button(new Rect(Screen.width-225, (Screen.height-100)+25, 200, 50), "Capture")){
guiLayer.enabled = false;
StartCoroutine(CaptureScreenshot());
}
}
IEnumerator CaptureScreenshot(){
yield return new WaitForEndOfFrame();
//TAKE SCREENSHOT CODE
yield return new WaitForEndOfFrame();
guiLayer.enabled = true;
}
I've tried removing the re-enable line at the end of the CaptureScreenshot line but the GUI stays throughout. I've even tried adding the guiLayer.enabled = false line to the Start() function with the hope that this'll illustrate whether or not the line itself is working but it's not.
Can anyone help?
Answer by danhanly · Sep 30, 2013 at 10:32 AM
Instead of disabling the GUILayer directly, I adjusted how the button action is called and instead added a boolean to turn the gui display on and off.
It works now.
if (showGUI){
if(GUI.Button(new Rect(Screen.width-225, (Screen.height-100)+25, 200, 50), "Capture")){
StartCoroutine(PauseForScreenshot());
}
}
IEnumerator PauseForScreenshot(){
showGUI = false;
yield return new WaitForSeconds(0.1f);
CaptureScreenshot();
yield return new WaitForSeconds(0.1f);
showGUI = true;
}
I noticed whilst enabling and disabling GUILayer and GUITextures that, on re-enable the Start() routine is not run again.
Thank you for this! I was having this same problem and this fixed it for me.
Your answer
![](https://koobas.hobune.stream/wayback/20220613115048im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to remove GUILayer? 2 Answers
HitTest giving NullReferenceException when the mouse is not over some GUI element 1 Answer