The following script can be put on any UI gameObject to control whether it is hidden when the scene starts.
In Project2, we'll use this script on panel associated with scene dialog.
With this attached script will be hidden when the scene is initially loaded.
This script can be used on the OptionPanel which controls buttons for changing scenes. A checkbox in the inspector provides an option to have the panel start in open state when the scene loads.
The Panel must have a CanvasGroup Component.
When working with SimpleDialog, or DialogManager, the OptionPanel should be set as the Next Panel To Open in the SimpleDialog or DialogManager script.
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;publicclassHide_Show_Panel : MonoBehaviour{CanvasGroup panelCG; //must be on same gameObject as this scriptpublic bool showOnStart =false; //default is hiddenpublicButton closeButton; //clicking will hidepublicButton openButton; //clicking will showpublicCanvasGroup nextPanelToOpen;// Use this for initializationvoidStart() { panelCG =GetComponent<CanvasGroup>(); //must have CanvasGroup componentif (!showOnStart) {HidePanel(); //hide at start }else {ShowPanel(); //show at start }//if buttons are set in inspector, configure to open/close panel if (closeButton !=null) {closeButton.onClick.AddListener(HidePanel); }if (openButton !=null) {closeButton.onClick.AddListener(ShowPanel); } }publicvoidShowPanel() {Utility.ShowCG(panelCG); }publicvoidHidePanel() {Utility.HideCG(panelCG); }publicvoidOpenNextPanel() {if( nextPanelToOpen !=null) {Utility.ShowCG(nextPanelToOpen); } }}