Question by
duartera · Jul 29, 2020 at 05:03 AM ·
scripting problemcanvassetactive
Hide/Unhide Canvas in AR Project
Hi guys,
I'm trying to hide/unhide a Canvas by scripting, i've already read the documentation to do so, but im not able to make it work (My Canvas has 3 buttons).
This is my code (I also tried without the lines UI.GetComponent<Canvas>().enabled = true;
and UI.GetComponent<Canvas>().enabled = false;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ShowHideCanvas : MonoBehaviour
{
public Canvas UI;
public bool CanvasACtive;
// Start is called before the first frame update
void Start()
{
CanvasACtive = true;
}
// Update is called once per frame
void Update()
{
if (CanvasACtive == true)
{
UI.GetComponent<Canvas>().enabled = true;
UI.gameObject.SetActive(true);
}
else
{
UI.GetComponent<Canvas>().enabled = false;
UI.gameObject.SetActive(false);
}
}
}
Any suggestion?
Thanks in advance.
Diego.
Comment
Your answer
Follow this Question
Related Questions
Game object not enabled after SetActive(true). 1 Answer
How to position world space canvas from script 0 Answers
I want to input GameObject(has camera component) to Canvas's EventCamera by using Scripts 0 Answers
AddListener fuction throwing a NullReferenceException error 1 Answer
How do I change the scene after 2 objects are destroyed (SetActive false) 1 Answer