- Home /
Can't enable canvas
I can't seem to enable a Canvas what so ever. I watched a video(more than 10 times) and followed everything EXACTLY. And I ended up with this script. The Canvas.enable = false; and Canvas.enable = true; does not seem to be functioning.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PauseMenu : MonoBehaviour
{
public Canvas pausemenu;
public Button pause;
public Button restart;
public Button cont;
public Button quit;
public Button mainMenu;
void Start()
{
pausemenu = pausemenu.GetComponent<Canvas> ();
pause = pause.GetComponent<Button>();
restart = restart.GetComponent<Button> ();
cont = cont.GetComponent<Button> ();
quit = quit.GetComponent<Button> ();
mainMenu = mainMenu.GetComponent<Button> ();
pausemenu.enabled = false;
}
public void PauseGame()
{
pausemenu.enabled = true;
}
}
Also, your question is very hard to read and your script isn't formatted correctly.
although already answered, I formated your question for better readability, if someone stumbles across this, looking for help. Please try to use a modicum of formatting and care before posting a question.
Answer by KdRWaylander · Jul 16, 2015 at 11:39 AM
@meat5000 is right, you need to use SetActive(bool state)
instead of .enabled
Why ? Because .enabled
deals with components only and SetActive()
with gameobjects only !
Code is then:
public void PauseGame () {
pausemenu.gameObject.SetActive(true);
}
You need to go back to the GameObject with .gameObject since pausemenu is a component. If pausemenu was a GameObecjt, you wouldn't need this step and just have to use .SetActive()
Thank you @$$anonymous$$dRWaylander! 3 hours of trying different ways to get a Scare Screen image to popup after clicking the start game button, and I finally stumble onto this thread. "SetActive" who woulda thunk it...
Cheers! $$anonymous$$ark
Your answer
Follow this Question
Related Questions
How to instantiate a prefab between Canvas and a Button? 0 Answers
On Click paramaters disappear from button prefab? 5 Answers
If button highlighted 2 Answers
Rect to RectTransform on overlay Canvas? 1 Answer
Event trigger for instantiated objects 0 Answers