- Home /
Background color and structure disappear when enabling GUI Canvas
I'm trying to create a simple pause menu which gets shown when the user presses escape while in game. My structure of canvas and sub-objects looks like this:
My script (C#) looks like this, it's attached to the gameController empty object in the root of the objects hierarchy:
public class MenuController : MonoBehaviour {
public Canvas pauseCanvas;
void Start () {
}
void Update () {
if(Input.GetKey(KeyCode.Escape)) {
Debug.Log("escape pressed");
pauseCanvas.enabled = true;
}
}
}
==> For variable pauseCanvas I dragged the object with name 'gui' (the Canvas) to the variable input in the Inspector window. I disable the Canvas by default in the Inspector and the enable it using above code, which results in the background and button layout and such being gone.
When I press Escape this is what I want to see: http://i.imgur.com/RoXUH7a.png
This is what I get: http://i.imgur.com/nPA6eF8.png
Hope anyone can help, thanks in advance!
Your answer
Follow this Question
Related Questions
Gui Toggle help 2 Answers
Tutorials for 2D game GUI 2 Answers
I have been struggling with a GUI texture for over a week now. What am I doing wrong? 1 Answer
Using Canvas/Gui with splitscreen(several cameras) 0 Answers
GUI not work after building 1 Answer